SONARJAVA-6425 Support records in S1068#5644
SONARJAVA-6425 Support records in S1068#5644tomasz-tylenda-sonarsource wants to merge 3 commits into
Conversation
| record MyRecord(int a) { | ||
| private static final int XYZ = 3; // Noncompliant | ||
| // ^^^ | ||
| } |
There was a problem hiding this comment.
💡 Edge Case: Test missing: record instance field false positive coverage
The test only covers private static final fields in records. Records can also have explicitly declared private instance fields (though rare). More importantly, record components generate implicit private final fields (e.g., int a in record MyRecord(int a)). It would strengthen confidence to add a test verifying the rule does NOT flag record component fields as unused, since they are accessed via the implicit accessor method. For example:
record MyRecordCompliant(int a) {
// 'a' should not be flagged
private static final int USED = 1;
int sum() { return a + USED; }
}This would guard against future regressions if the AST representation changes.
Was this helpful? React with 👍 / 👎
Done. The bot also talks about "explicitly declared private instance fields", but I don't think it is possible. |
|
Code Review ✅ Approved 1 resolved / 1 findingsUpdates UnusedPrivateFieldCheck to support Java records, resolving the false positive coverage issue for record instance fields. No additional findings detected. ✅ 1 resolved✅ Edge Case: Test missing: record instance field false positive coverage
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
UnusedPrivateFieldCheckto includeTree.Kind.RECORDinnodesToVisitand switch case.UnusedPrivateFieldCheck.javatest sources.This will update automatically on new commits.