Skip to content

SONARJAVA-6687 S2129 Java: add BigDecimal(String) to exceptions - #6052

Open
asya-vorobeva wants to merge 1 commit into
masterfrom
asya/update-S2129-desc
Open

SONARJAVA-6687 S2129 Java: add BigDecimal(String) to exceptions#6052
asya-vorobeva wants to merge 1 commit into
masterfrom
asya/update-S2129-desc

Conversation

@asya-vorobeva

Copy link
Copy Markdown
Contributor

BigDecimal.valueOf has no String overload, so new BigDecimal(String) has no equivalent alternative and should not be flagged.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6687

Comment on lines +32 to +33
<p><code>BigDecimal</code> constructor with a <code>String</code> argument is also ignored because <code>BigDecimal.valueOf</code> does not accept a
<code>String</code>, leaving no equivalent alternative.</p>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Quality: Rule description edited in generated (RSPEC-sourced) folder

S2129.html lives in sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java, whose README states the files are generated from RSPEC and that PRs modifying descriptions there will be rejected; sonarpedia.json points rule-api at this same directory. Editing the HTML directly means the new Exceptions paragraph is silently reverted the next time rule metadata is regenerated by rule-api (which also bumps latest-update — unchanged in this diff). The wording change should be made in RSPEC and pulled in via a rule-api metadata update instead of hand-editing the generated file.

Was this helpful? React with 👍 / 👎

Comment on lines 29 to +33
<h3>Exceptions</h3>
<p><code>BigDecimal</code> constructor with a <code>double</code> argument is ignored as using <code>valueOf</code> instead might change the resulting
value. See {rule:java:S2111}.</p>
<p><code>BigDecimal</code> constructor with a <code>String</code> argument is also ignored because <code>BigDecimal.valueOf</code> does not accept a
<code>String</code>, leaving no equivalent alternative.</p>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Quality: Exceptions list implies non-double/String BigDecimal ctors are flagged

StringPrimitiveConstructorCheck's matchers contains no BigDecimal entry at all, so no BigDecimal constructor is ever reported (e.g. new BigDecimal(42L), for which BigDecimal.valueOf(long) does exist, raises nothing). By listing only the double and String overloads as exceptions while the title and intro keep advertising BigDecimal as a flagged class, the updated description tells users that the remaining overloads are reported, which they are not. Either state that all BigDecimal constructors are ignored or drop BigDecimal from the title/intro claim.

Was this helpful? React with 👍 / 👎

@lijun-chen-sonarsource lijun-chen-sonarsource left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

BigDecimal.valueOf has no String overload, so new BigDecimal(String) has no equivalent alternative and should not be flagged.
@asya-vorobeva
asya-vorobeva force-pushed the asya/update-S2129-desc branch from 142b08b to c020dba Compare August 28, 2026 10:59
@gitar-bot

gitar-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown
Code Review ⚠️ Changes requested 0 resolved / 2 findings

Updates rule description for S2129 to exclude BigDecimal(String) from exceptions, but edits a generated RSPEC-sourced file directly which will be overwritten on the next metadata regeneration. Additionally, the updated exception list implies other BigDecimal constructors are flagged when no BigDecimal matchers exist in the implementation.

⚠️ Quality: Rule description edited in generated (RSPEC-sourced) folder

📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:32-33

S2129.html lives in sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java, whose README states the files are generated from RSPEC and that PRs modifying descriptions there will be rejected; sonarpedia.json points rule-api at this same directory. Editing the HTML directly means the new Exceptions paragraph is silently reverted the next time rule metadata is regenerated by rule-api (which also bumps latest-update — unchanged in this diff). The wording change should be made in RSPEC and pulled in via a rule-api metadata update instead of hand-editing the generated file.

💡 Quality: Exceptions list implies non-double/String BigDecimal ctors are flagged

📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:2-3 📄 sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:29-33

StringPrimitiveConstructorCheck's matchers contains no BigDecimal entry at all, so no BigDecimal constructor is ever reported (e.g. new BigDecimal(42L), for which BigDecimal.valueOf(long) does exist, raises nothing). By listing only the double and String overloads as exceptions while the title and intro keep advertising BigDecimal as a flagged class, the updated description tells users that the remaining overloads are reported, which they are not. Either state that all BigDecimal constructors are ignored or drop BigDecimal from the title/intro claim.

🤖 Prompt for agents
Code Review: Updates rule description for `S2129` to exclude `BigDecimal(String)` from exceptions, but edits a generated RSPEC-sourced file directly which will be overwritten on the next metadata regeneration. Additionally, the updated exception list implies other `BigDecimal` constructors are flagged when no `BigDecimal` matchers exist in the implementation.

1. ⚠️ Quality: Rule description edited in generated (RSPEC-sourced) folder
   Files: sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:32-33

   S2129.html lives in sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java, whose README states the files are generated from RSPEC and that PRs modifying descriptions there will be rejected; sonarpedia.json points rule-api at this same directory. Editing the HTML directly means the new Exceptions paragraph is silently reverted the next time rule metadata is regenerated by rule-api (which also bumps `latest-update` — unchanged in this diff). The wording change should be made in RSPEC and pulled in via a rule-api metadata update instead of hand-editing the generated file.

2. 💡 Quality: Exceptions list implies non-double/String BigDecimal ctors are flagged
   Files: sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:2-3, sonar-java-plugin/src/main/resources/org/sonar/l10n/java/rules/java/S2129.html:29-33

   StringPrimitiveConstructorCheck's `matchers` contains no BigDecimal entry at all, so no BigDecimal constructor is ever reported (e.g. `new BigDecimal(42L)`, for which `BigDecimal.valueOf(long)` does exist, raises nothing). By listing only the `double` and `String` overloads as exceptions while the title and intro keep advertising BigDecimal as a flagged class, the updated description tells users that the remaining overloads are reported, which they are not. Either state that all `BigDecimal` constructors are ignored or drop BigDecimal from the title/intro claim.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.
Unblock → Override a blocking verdict and allow merging.

Comment with these commands to change the behavior for this request:

Auto-apply Compact Unblock
gitar auto-apply:on         
gitar display:verbose         
gitar unblock         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

Copy link
Copy Markdown
Contributor

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Fixed issues
0 Accepted issues

Measures
0 Security Hotspots
0 Dependency risks
No data about Coverage
No data about Duplication

See analysis details on SonarQube

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