Document that transform and transformAsync propagate exceptions thrown by the function - #8696
Closed
cindykrafft wants to merge 1 commit into
Closed
cindykrafft wants to merge 1 commit into
cindykrafft wants to merge 1 commit into
Conversation
…hrown by the function. `Futures.transform`, `Futures.transformAsync`, `FluentFuture.transform`, and `FluentFuture.transformAsync` already document that a failure of the input is propagated to the returned `Future`, but not what happens when the function itself throws. In that case, the returned `Future` fails with the thrown exception. (`catching` and `catchingAsync` already document the equivalent behavior for their fallback.) Fixes google#2690 Claude-Session: https://claude.ai/code/session_01X59fWmqnA4Nmb9rggkTP7n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Javadoc for
Futures.transform,Futures.transformAsync,FluentFuture.transformandFluentFuture.transformAsyncsays that if the input fails, "the returned {@code Future} fails with the same exception (and the function is not invoked)" (e.g. Futures.java:465-466). As far as I can see, it does not say what happens when the function itself throws. This adds the following sentence right after the existing one in all four methods:This is a Javadoc-only change.
catchingandcatchingAsync(in bothFuturesandFluentFuture) already say "If, during the invocation of {@code fallback}, an exception is thrown, this exception is used as the result of the output {@code Future}", so they are not changed.Fixes #2690
Verification:
AbstractTransformFuture.run(), aThrowablefromdoTransformis caught withcatch (Throwable t)and passed tosetException(t)(AbstractTransformFuture.java:125-130).directExecutor()and once with a thread pool. In every case the returned future failed, andExecutionException.getCause()was the same instance the function threw:transformwith aRuntimeExceptionor anError, whether the input was already done or completed latertransformAsyncwith aRuntimeException, a checked exception or anErrorFluentFutureAsyncFunctionreturnsnull, the returned future fails with aNullPointerException("AsyncFunction.apply returned null instead of a Future..."). This PR does not document that case.Testing:
./mvnw -pl guava,guava-testlib,guava-tests test -Dtest.include="**/FuturesTest.java,**/FluentFutureTest.java": 169 tests (160 in FuturesTest, 9 in FluentFutureTest), 0 failures, 0 errors../mvnw -pl guava javadoc:javadoc: BUILD SUCCESS, and the new sentence appears in the generatedFutures.htmlandFluentFuture.html.