nahsra / WebGoat_12_23

Other
0 stars 2 forks source link

(Sonar) Fixed finding: "Utility classes should not have public constructors" #34

Closed pixeebot[bot] closed 3 months ago

pixeebot[bot] commented 3 months ago

Remediation

This change fixes "Utility classes should not have public constructors" (id = java:S1118) identified by Sonar.

Details

This change adds private constructors to utility classes. Utility classes are only meant to be accessed statically. Since they're not meant to be instantiated, we can use the Java's code visibility protections to hide the constructor and prevent unintended or malicious access.

Our changes look something like this:

   public class Utils {
+    private Utils() {}
     ...
More reading * [https://rules.sonarsource.com/java/RSPEC-1118/](https://rules.sonarsource.com/java/RSPEC-1118/)

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/avoid-implicit-public-constructor-s1118

sonarcloud[bot] commented 3 months 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