Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarcloud codemod - Harden String Parse to primitives (Integer/Float constructor cases) #252

Merged
merged 37 commits into from
Dec 3, 2023

Conversation

carlosu7
Copy link
Contributor

@carlosu7 carlosu7 commented Dec 2, 2023

Finish Sonarcloud codemod (HardenStringParseToPrimitivesCodemod) to enforce the appropriate parsing technique for converting Strings to primitive types in the codebase.

This PR handles the new Float//new Integer constructor cases (ObjectCreationExpr nodes).

Previous PR that handles .valueOf cases -> #250

Sonar rule reference https://rules.sonarsource.com/java/RSPEC-2130/

sonar cloud issues related to string-to-primitive conversion: https://sonarcloud.io/project/issues?fileUuids=AYvtrjqILCzGLicz7AY_&resolved=false&id=nahsra_WebGoat_10_23

IMPORTANT NOTE!!!!

As you can see on the Test.java.before the following cases are not reported by sonarcloud:

float myFloatValue = (new Float(myNum)).floatValue();
int myIntValue = (new Integer(myNum)).intValue();

Therefore, those cases are not being fixed

      float myFloatValue = (new Float(myNum)).floatValue();
      int myIntValue = (new Integer(myNum)).intValue();
@carlosu7 carlosu7 requested a review from nahsra December 2, 2023 03:03
@carlosu7 carlosu7 self-assigned this Dec 2, 2023
@carlosu7 carlosu7 requested a review from nahsra December 2, 2023 19:13
Base automatically changed from sonar-codemod-integer-parseInt to main December 3, 2023 00:32
Copy link

sonarcloud bot commented Dec 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@carlosu7 carlosu7 merged commit c9fa81e into main Dec 3, 2023
6 checks passed
@carlosu7 carlosu7 deleted the sonar-codemod-harden-string-parsing-CONSTRUCTORS branch December 3, 2023 19:16
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