SONARJAVA-6506 Avoid suggesting records for DTO contracts#5695
Conversation
asya-vorobeva
left a comment
There was a problem hiding this comment.
Makes sense also to update RSpec desc for this rule and shortly list exceptions.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
asya-vorobeva
left a comment
There was a problem hiding this comment.
Generally LGTM, one little comment.
|
Code Review ✅ Approved 4 resolved / 4 findingsPrevents S6206 from suggesting record conversion for classes with serialization or framework contracts. Cleaned up redundant Externalizable checks and resolved dependency issues in test configuration. ✅ 4 resolved✅ Quality: FRAMEWORK_ANNOTATION_PREFIXES map keys are unused and stream is rebuilt per check
✅ Bug: Test depends on undeclared jars hardcoded from local ~/.m2 repo
✅ Bug: Test hardcodes local ~/.m2 jar paths instead of resolved classpath
✅ Quality: Redundant Externalizable subtype check in hasSerializationContract
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
Root cause
S6206 only checked structural record eligibility. That missed cases where converting a class to a record would change runtime behavior because serialization hooks or framework metadata define part of the class contract.
Validation
mvn -pl java-checks -am -Dtest=org.sonar.java.checks.RecordInsteadOfClassCheckTest -DfailIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false testgit diff --checkRSPEC
https://github.com/SonarSource/rspec/pull/7177