SONARJAVA-6454 : Rule S8714 - implement quickfix#5663
Conversation
… method invocation
Agentic Analysis: Early ResultsAgentic Analysis and Context Augmentation are available on your project. Here are some issues that could have been prevented. Follow the links to learn how to put them into action. 6 issue(s) found across 1 file(s):
Analyzed by SonarQube Agentic Analysis in 2.9 s |
tomasz-tylenda-sonarsource
left a comment
There was a problem hiding this comment.
The contents of the PR changed. Let me send you the comments I had. I'll finish the review when the contents is stable.
|
|
||
| public static List<Type> getCaughtTypes(CatchTree tree) { | ||
| VariableTree parameter = tree.parameter(); | ||
| if (parameter.type().is(Tree.Kind.UNION_TYPE)) { |
There was a problem hiding this comment.
Can we do ... instanceof UnionTypeTree unio.TypeTree and avoid cast below?
| /* This utility class should not be instantiated */ | ||
| } | ||
|
|
||
| public static List<Type> getCaughtTypes(CatchTree tree) { |
There was a problem hiding this comment.
This method should have a test.
There was a problem hiding this comment.
Done. But the test is actually more complicated and contains more logic than the method itself (it tests more test code than prod code)
| junitReplacement(failArguments, tryStatement, isTryBlock); | ||
| issueBuilder.withQuickFix(() -> | ||
| JavaQuickFix.newQuickFix(issueMessage).addTextEdit( | ||
| JavaTextEdit.replaceTree(tryStatement.tryKeyword(), replacements.replaceTryWith), |
There was a problem hiding this comment.
I commented out code here and the unit tests still passed. Is this at all executed in tests?
There was a problem hiding this comment.
Yes : currently unit testing quickfixes is very hard to setup because of improper logging, and those unit tests don't make much sense. They only assert that the list of edits matches the expected list of edits but not that the fixed version of the code matches the expected fixed code. Let me know if you find it strictly necessary to test this part, i can cover it (and make it fail if you comment it out).
Code Review ✅ Approved 5 resolved / 5 findingsImplements quickfix support for S8714 by introducing TryCatchUtils and handling JUnit/AssertJ transformations. Resolved issues include removing debug print statements, fixing wildcard imports, and preventing potential NPEs in catch block analysis. ✅ 5 resolved✅ Bug: Test comment typo '// NonCompliant' is not recognized by verifier
✅ Quality: Wildcard imports violate rule S2208 (self-dogfooding)
✅ Bug: Quickfix throws IndexOutOfBounds for try-block fail() without catch
✅ Quality: Leftover debug System.out.println in new test
✅ Edge Case: AssertJ quickfix misuses non-String fail() argument as fail message
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary by Gitar
AssertThrowsInsteadOfTryCatchFailCheckfor both JUnit and AssertJ.TryCatchUtilshelper to centralize catch block type extraction logic.getCaughtTypeslogic fromInterruptedExceptionCheckto the new sharedTryCatchUtilshelper.AssertThrowsInsteadOfTryCatchFailCheckSampleto correctly categorize JUnit failure cases and add new test coverage.TryCatchUtilsTestto verify catch block type resolution.Replacementsrecord to handle automated code transformations for JUnitassertThrowsand AssertJassertThatCodepatterns.This will update automatically on new commits.