SONARJAVA-6465 : Rule S8714 - fix quickfix indexoutofbound / NPE exception#5670
Conversation
|
I wasn't able to add a unit test for this fix :
|
tomasz-tylenda-sonarsource
left a comment
There was a problem hiding this comment.
I'll wait for the fix for NPE.
tomasz-tylenda-sonarsource
left a comment
There was a problem hiding this comment.
This is still attached to the old ticket, right>
| var isAssertJ = failMethodInvocation | ||
| .methodSymbol() | ||
| .owner() | ||
| .type() |
There was a problem hiding this comment.
I just realized that NPE is possible here. Let's guard against if just in case.
var failOwner = failMethodInvocation.methodSymbol().owner();
if (failOwner == null) {
return;
}
var isAssertJ = failOwner.(...)
There was a problem hiding this comment.
It should not be possible as this point is not reached if owner is null (will not match any fail method in UnitTestUtils), but lets add this guard anyway for safety
|
Code Review ✅ Approved 5 resolved / 5 findingsResolves IndexOutOfBoundsException in the quickfix for Rule S8714 by adding safeguards for null method owners and handling parameterless fail() calls. Refactors try-with-resources generation to ensure valid output and updates AssertJ dependencies. ✅ 5 resolved✅ Quality: Unused Optional import and wildcard import added
✅ Bug: Quickfix emits 'Throwable' instead of 'Throwable.class'
✅ Bug: Try-with-resources quickfix generates non-compiling Java
✅ Quality: New assertJ fail() test does not verify the quickfix output
✅ Quality: Misleading comment: test uses fail with argument, not without
OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |




Despite AssertJ doc pretends fail always has a string argument message, it is not the case in practice : causing a index out of bound exception
Summary by Gitar
IndexOutOfBoundsExceptioninAssertThrowsInsteadOfTryCatchFailCheckby handlingfail()calls without arguments.nullmethod owners duringfail()invocation analysis.ThrowabletoThrowable.classin expected type resolution.JavaTextEditgeneration to handle diverseTryStatementTreeconfigurations, includingtry-with-resourceswithoutcatchorfinally.assertj-coreto3.27.7and updated test samples accordingly.This will update automatically on new commits.