Commit 5c82668
authored
(Sonar) Fixed finding: "Utility classes should not have public constructors" (#395)
## Remediation
This change fixes "Utility classes should not have public constructors"
(id = [java:S1118](https://rules.sonarsource.com/java/RSPEC-1118/))
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:
```diff
public class Utils {
+ private Utils() {}
...
```
<details>
<summary>More reading</summary>
*
[https://rules.sonarsource.com/java/RSPEC-1118/](https://rules.sonarsource.com/java/RSPEC-1118/)
</details>
🧚🤖 Powered by Pixeebot
[Feedback](https://ask.pixee.ai/feedback) |
[Community](https://pixee-community.slack.com/signup#/domain-signup) |
[Docs](https://docs.pixee.ai/) | Codemod ID:
[sonar:java/avoid-implicit-public-constructor-s1118](https://docs.pixee.ai/codemods/java/sonar_java_avoid-implicit-public-constructor-s1118)

<!--{"type":"DRIP","codemod":"sonar:java/avoid-implicit-public-constructor-s1118"}-->
---------
Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
Co-authored-by: pixeebot[bot] <pixeebot[bot]@users.noreply.github.com>1 parent ec403a7 commit 5c82668
File tree
6 files changed
+12
-0
lines changed- core-codemods/src/main/java/io/codemodder/codemods
- framework
- codemodder-base/src/main/java/io/codemodder
- ast
- codemodder-testutils-llm/src/main/java/io/codemodder/testutils/llm
6 files changed
+12
-0
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
0 commit comments