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

CompletableFutureTask, fix spurious error logging when cancelling #3135

Merged
merged 3 commits into from
Sep 6, 2024

Conversation

jonenst
Copy link
Contributor

@jonenst jonenst commented Sep 6, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Does this PR already have an issue describing the problem?

NO

What kind of change does this PR introduce?

bug fix

What is the current behavior?

When calling cancel(true), the CompletableFutureTask was throwing a NullPointerException in its run method because cancel(true) causes future.get() to throw a CancellationException without a cause (null) and completeExceptionally requires a non null Exception

the exception was thrown to the executor and the very end. Executors usually catch and ignore everything (just logs to stdout) so the problem was just ugly logs and a slight performance drop. But also maybe in some cases an exception with a cause was thrown and the bad exception was used to completeexceptionally the completablefuturetask, not sure.

What is the new behavior (if this is a feature change)?
no exception, and we are sure that we always completeexceptionally with the correct exception

Does this PR introduce a breaking change or deprecate an API?

  • Yes
  • No

Other information:

This was a regression from 5bef72f, the actual code is reverted to the previous version (except changing throwable to exception to please avoid sonar warnings I guess)

When calling cancel(true), the CompletableFutureTask was throwing
a NullPointerException in its run method because cancel(true)
causes future.get() to throw a CancellationException without a cause (null)
and completeExceptionally requires a non null Exception

the exception was thrown to the executor and the very end. Executors usually catch and
ignore everything (just logs to stdout) so the problem was just ugly logs and a slight
performance drop.

This was a regression from 5bef72f, the actual code is reverted to the previous version
(except changing throwable to exception to please avoid sonar warnings I guess)
The code change was not logical, we need to unwrap the cause when we have an ExecutionException
and we also need to not unwrap the cause otherwise.

Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
@jonenst jonenst requested review from geofjamg and rolnico September 6, 2024 15:00
jonenst and others added 2 commits September 6, 2024 17:36
…utureTaskTest.java

Co-authored-by: Nicolas Rol <nicolas.rol@rte-france.com>
Signed-off-by: Jon Harper <jon.harper87@gmail.com>
…utureTaskTest.java

Co-authored-by: Nicolas Rol <nicolas.rol@rte-france.com>
Signed-off-by: Jon Harper <jon.harper87@gmail.com>
Copy link

sonarqubecloud bot commented Sep 6, 2024

@jonenst jonenst dismissed rolnico’s stale review September 6, 2024 15:55

accepted changes

@jonenst jonenst merged commit e0287a9 into main Sep 6, 2024
7 checks passed
@jonenst jonenst deleted the fixcompletablefuturetaskcancelthrowstoexecutor branch September 6, 2024 15:55
geofjamg pushed a commit that referenced this pull request Sep 18, 2024
)

When calling cancel(true), the CompletableFutureTask was throwing
a NullPointerException in its run method because cancel(true)
causes future.get() to throw a CancellationException without a cause (null)
and completeExceptionally requires a non null Exception

the exception was thrown to the executor and the very end. Executors usually catch and
ignore everything (just logs to stdout) so the problem was just ugly logs and a slight
performance drop.

This was a regression from 5bef72f, the actual code is reverted to the previous version
(except changing throwable to exception to please avoid sonar warnings I guess)
The code change was not logical, we need to unwrap the cause when we have an ExecutionException
and we also need to not unwrap the cause otherwise.

Signed-off-by: HARPER Jon <jon.harper87@gmail.com>
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.

3 participants