nahsra / WebGoat_12_23

Other
0 stars 2 forks source link

(Sonar) Fixed finding: "Local variables should not be declared and then immediately returned or thrown" #40

Closed pixeebot[bot] closed 1 month ago

pixeebot[bot] commented 1 month ago

Remediation

This change fixes "Local variables should not be declared and then immediately returned or thrown" (id = java:S1488) identified by Sonar.

Details

This change removes intermediate variables who are only created to be thrown or returned in the next statement. This makes the code more readable, which makes reviewing the code for issues easier.

Our changes look something like this:

    public LocaleResolver localeResolver() { 
-       SessionLocaleResolver localeResolver = new SessionLocaleResolver();
-       return localeResolver;
+       return new SessionLocaleResolver();
    }
    public void process() { 
-       Exception ex = new Exception();
-       throw ex;
+       throw new Exception();
    }
More reading * [https://rules.sonarsource.com/java/RSPEC-1488/](https://rules.sonarsource.com/java/RSPEC-1488/)

I have additional improvements ready for this repo! If you want to see them, leave the comment:

@pixeebot next

... and I will open a new PR right away!

🧚🤖 Powered by Pixeebot

Feedback | Community | Docs | Codemod ID: sonar:java/remove-redundant-variable-creation-s1488

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud