SONARJAVA-4376 Fix S2129 in the case of missing semantic#5123
Merged
romainbrenguier merged 1 commit intomasterfrom May 5, 2025
Merged
SONARJAVA-4376 Fix S2129 in the case of missing semantic#5123romainbrenguier merged 1 commit intomasterfrom
romainbrenguier merged 1 commit intomasterfrom
Conversation
| CheckVerifier.newVerifier() | ||
| .onFile(mainCodeSourcesPath("checks/StringPrimitiveConstructorCheckSample.java")) | ||
| .withCheck(new StringPrimitiveConstructorCheck()) | ||
| .withoutSemantic() |
Contributor
There was a problem hiding this comment.
Let's have two tests - one with semantics and one without. We usually call them test and test_without_semantics. You may need two sample files.
| Short myShort = (short) 0; | ||
| } | ||
|
|
||
| String withoutSemantic(HttpResponse response) throws IOException { |
Contributor
There was a problem hiding this comment.
Maybe we can make the test method names more uniform (fromHttp and fromGuava) and add a comment explaining that these sample require special treatment when semantics is not available?
When semantic is missing for the argument of String constructor for instance, the parser takes a guess at which constructor it is and this may cause some false positives. The fix in this PR, skips the case where we detect an unknown in the argument types. The second sample is coming from SONARJAVA-5388
dee7ea9 to
b8367dc
Compare
|
tomasz-tylenda-sonarsource
approved these changes
May 5, 2025
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.




SONARJAVA-4376
When semantic is missing for the argument of String constructor for instance, the parser takes a guess at which constructor it is and this may cause some false positives. The fix in this PR, skips the case where we detect an unknown in the argument types. The second sample is comming from SONARJAVA-5388