Repository navigation
Keep calls that may throw inside the AssertThrowsOnLastStatement lambda - #1306
Merged
Merged
Conversation
timtebeek
marked this pull request as ready for review
November 17, 2026 19:36
Member
Author
|
Thanks again for the report @slachiewicz! Release should go out tonight. |
51 of 76 tasks
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.
Addresses C14 in #1211, including the case reported in #1211 (comment).
AssertThrowsOnLastStatementmoved calls out of theassertThrowslambda without checking whether they throw. In theIOUtilTestcase from apache/maven-shared-utils,IOUtil.toString(..., "junk")was moved out of the last statement's arguments. The test no longer compiled, because the call throws a checkedUnsupportedEncodingException. The same happened to earlier statements in the block.A call now stays in the lambda when it declares the expected exception, a subclass of it, or a parent class of it. In Java, a call also stays when it declares a checked exception the test method doesn't. Calls without a method type count as possibly throwing. A flagged argument of the last statement stays inline while the other arguments are still moved out. A flagged earlier statement leaves the whole
assertThrowsunchanged.Also in this PR:
byte[] bytesinstead ofObject bytes. Types that can't be written out, such as generic type variables, stay inline instead of being declared asObject.() -> {}lambda no longer deletes theassertThrowsstatement.@Issuelink to a non-existent issue number.getRecipeList()and keep cleanups local to the changed element #1230.The C14 suspicion of duplicate names from sibling
assertThrowscalls is not addressed here. The recipe description still warns that earlier statements can throw; that remains true for unchecked exceptions a method doesn't declare.Verified with
./gradlew test: 2556 tests, 0 failures. The six new tests inAssertThrowsOnLastStatementTestcover the reported case and the cases above.