Skip to content

SONARJAVA-4376 Fix S2129 in the case of missing semantic#5123

Merged
romainbrenguier merged 1 commit intomasterfrom
romain/fp/new-string-missing-semantic
May 5, 2025
Merged

SONARJAVA-4376 Fix S2129 in the case of missing semantic#5123
romainbrenguier merged 1 commit intomasterfrom
romain/fp/new-string-missing-semantic

Conversation

@romainbrenguier
Copy link
Copy Markdown
Contributor

@romainbrenguier romainbrenguier commented May 2, 2025

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

@romainbrenguier romainbrenguier marked this pull request as ready for review May 2, 2025 14:51
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/StringPrimitiveConstructorCheckSample.java"))
.withCheck(new StringPrimitiveConstructorCheck())
.withoutSemantic()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@romainbrenguier romainbrenguier force-pushed the romain/fp/new-string-missing-semantic branch from dee7ea9 to b8367dc Compare May 5, 2025 09:45
@sonarqube-next
Copy link
Copy Markdown

sonarqube-next Bot commented May 5, 2025

@romainbrenguier romainbrenguier merged commit 33b4cc1 into master May 5, 2025
17 checks passed
@romainbrenguier romainbrenguier deleted the romain/fp/new-string-missing-semantic branch May 5, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants