Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: latter task cannot be executed because taskResult.getLogs() can return null and decide(workflowId) will not be invoked #334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ColinZou
Copy link

@ColinZou ColinZou commented Dec 12, 2024

…return null and decide(workflowId) will not be invoked

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • WHOSUSING.md
  • Other (please describe):

NOTE: Please remember to run ./gradlew spotlessApply to fix any format violations.

Changes in this PR
Added null check for return value taskResult.getLogs before saving task execution log when update task.

…return null and decide(workflowId) will not be invoked
@ColinZou
Copy link
Author

@jmigueprieto could you please check this PR. The input logs of TaskResult can be null somehow and nullpointer exception throws.

@jmigueprieto
Copy link
Contributor

@jmigueprieto could you please check this PR. The input logs of TaskResult can be null somehow and nullpointer exception throws.

Hey @ColinZou - Thanks for bringing this up. I'll take a look.

Copy link
Contributor

@jmigueprieto jmigueprieto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add a test or explain the execution path that leads to a NPE
  • Change Optional usage.

executionDAOFacade.addTaskExecLog(taskResult.getLogs());

List<TaskExecLog> taskLogs = taskResult.getLogs();
Optional.ofNullable(taskLogs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ColinZou - A TaskResult instance is initialized with logs as an empty List. A NPE could only happen if taskResult.setLogs(null) is called before updateTask(taskResult).

Could you please add a test to reproduce the issue or explain the execution path? Thanks!

Also, I would much rather do a if null check instead of Optional because:

  1. Overhead: very minimal but wrapping taskLogs in an Optional introduces some.
  2. Not the intended use case: Optional is primarily meant for return types rather than as a replacement for null checks in existing code. (Check the [javadoc])(https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Optional.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants