Skip to content

Commit 6bf7412

Browse files
SONARJAVA-4524 Update rules metadata (#4408)
1 parent e44d516 commit 6bf7412

File tree

144 files changed

+2278
-1306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2278
-1306
lines changed

its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public void javaCheckTestSources() throws Exception {
188188
* No differences would mean that we find the same issues with and without the bytecode and libraries
189189
*/
190190
String differences = Files.readString(pathFor(TARGET_ACTUAL + PROJECT_KEY + "-no-binaries_differences"));
191-
assertThat(differences).isEqualTo("Issues differences: 3269");
191+
assertThat(differences).isEqualTo("Issues differences: 3265");
192192
}
193193

194194
private static Path pathFor(String path) {

its/ruling/src/test/resources/autoscan/autoscan-diff-by-rules.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@
161161
"falseNegatives": 0,
162162
"falsePositives": 0
163163
},
164-
{
165-
"ruleKey": "S1114",
166-
"hasTruePositives": true,
167-
"falseNegatives": 0,
168-
"falsePositives": 0
169-
},
170164
{
171165
"ruleKey": "S1116",
172166
"hasTruePositives": true,
@@ -587,12 +581,6 @@
587581
"falseNegatives": 11,
588582
"falsePositives": 0
589583
},
590-
{
591-
"ruleKey": "S1610",
592-
"hasTruePositives": true,
593-
"falseNegatives": 4,
594-
"falsePositives": 0
595-
},
596584
{
597585
"ruleKey": "S1611",
598586
"hasTruePositives": true,
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Shared naming conventions allow teams to collaborate efficiently. This rule checks that all method names match a provided regular expression.</p>
3-
<h3>Noncompliant code example</h3>
4-
<p>With default provided regular expression <code>^[a-z][a-zA-Z0-9]*$</code>:</p>
2+
<p>Shared naming conventions allow teams to collaborate efficiently.</p>
3+
<p>This rule raises an issue when a method name does not match a provided regular expression.</p>
4+
<p>For example, with the default provided regular expression <code>^[a-z][a-zA-Z0-9]*$</code>, the method:</p>
55
<pre>
6-
public int DoSomething(){...}
6+
public int DoSomething(){...} // Noncompliant
77
</pre>
8-
<h3>Compliant solution</h3>
8+
<p>should be renamed to</p>
99
<pre>
1010
public int doSomething(){...}
1111
</pre>
1212
<h3>Exceptions</h3>
1313
<p>Overriding methods are excluded.</p>
1414
<pre>
1515
@Override
16-
public int Do_Something(){...}
16+
public int Do_Something(){...} // Compliant by exception
1717
</pre>
1818

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S101.html

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Shared coding conventions allow teams to collaborate effectively. This rule allows to check that all class names match a provided regular
3-
expression.</p>
4-
<h3>Noncompliant code example</h3>
5-
<p>With default provided regular expression <code>^[A-Z][a-zA-Z0-9]*$</code>:</p>
2+
<p>Shared naming conventions allow teams to collaborate efficiently.</p>
3+
<p>This rule raises an issue when a class name does not match a provided regular expression.</p>
4+
<p>For example, with the default provided regular expression <code>^[A-Z][a-zA-Z0-9]*$</code>, the class:</p>
65
<pre>
7-
class my_class {...}
6+
class my_class {...} // Noncompliant
87
</pre>
9-
<h3>Compliant solution</h3>
8+
<p>should be renamed to</p>
109
<pre>
1110
class MyClass {...}
1211
</pre>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Having to scroll horizontally makes it harder to get a quick overview and understanding of any piece of code.</p>
2+
<p>Scrolling horizontally to see a full line of code lowers the code readability.</p>
33

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<h2>Why is this an issue?</h2>
2-
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to
3-
maintain. Above a specific threshold, it is strongly advised to refactor it into smaller pieces of code which focus on well defined tasks. Those
4-
smaller files will not only be easier to understand but also probably easier to test.</p>
2+
<p>A source file that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and, therefore, to
3+
maintain.</p>
4+
<p>Above a specific threshold, refactor the file into smaller files whose code focuses on well-defined tasks. Those smaller files will be easier to
5+
understand and easier to test.</p>
56

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Developers should not need to configure the tab width of their text editors in order to be able to read source code.</p>
3-
<p>So the use of the tabulation character must be banned.</p>
2+
<p>The tab width can differ from one development environment to another. Using tabs may require other developers to configure their environment (text
3+
editor, preferences, etc.) to read source code.</p>
4+
<p>That is why using spaces is preferable.</p>
45

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Most of the time a block of code is empty when a piece of code is really missing. So such empty block must be either filled or removed.</p>
3-
<h3>Noncompliant code example</h3>
2+
<p>An empty code block is confusing. It will require some effort from maintainers to determine if it is intentional or indicates the implementation is
3+
incomplete.</p>
44
<pre>
5-
for (int i = 0; i &lt; 42; i++){} // Empty on purpose or missing piece of code ?
5+
for (int i = 0; i &lt; 42; i++){} // Noncompliant: is the block empty on purpose, or is code missing?
66
</pre>
7+
<p>Removing or filling the empty code blocks takes away ambiguity and generally results in a more straightforward and less surprising code.</p>
78
<h3>Exceptions</h3>
8-
<p>When a block contains a comment, this block is not considered to be empty unless it is a <code>synchronized</code> block. <code>synchronized</code>
9-
blocks are still considered empty even with comments because they can still affect program flow.</p>
9+
<p>The rule ignores code blocks that contain comments unless they are <code>synchronized</code> blocks because these can affect program flow.</p>
1010

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<h2>Why is this an issue?</h2>
2-
<p>Inheritance is certainly one of the most valuable concepts in object-oriented programming. It’s a way to compartmentalize and reuse code by
3-
creating collections of attributes and behaviors called classes which can be based on previously created classes. But abusing this concept by creating
4-
a deep inheritance tree can lead to very complex and unmaintainable source code. Most of the time too deep of an inheritance tree is due to bad object
5-
oriented design which leads to a systematic use of 'inheritance' when 'composition' would be better suited.</p>
6-
<p>This rule raises an issue when the inheritance tree, starting from <code>Object</code> has a greater depth than is allowed.</p>
7-
<p>For the parameter of the rule, the following rules are applied:</p>
2+
<p>Inheritance is one of the most valuable concepts in object-oriented programming. It’s a way to categorize and reuse code by creating collections of
3+
attributes and behaviors called classes, which can be based on previously created classes.</p>
4+
<p>But abusing this concept by creating a deep inheritance tree can lead to complex and unmaintainable source code. Often, an inheritance tree
5+
becoming too deep is the symptom of systematic use of "inheritance" when other approaches like "composition" would be better suited.</p>
6+
<p>This rule raises an issue when the inheritance tree, starting from <code>Object</code>, has a greater depth than is allowed.</p>
7+
<p>The rule has one parameter to filter out classes of the count of inheritance. The following rules apply to define this parameter:</p>
88
<ul>
99
<li> <code>?</code> matches a single character </li>
1010
<li> <code>*</code> matches zero or more characters </li>
1111
<li> <code>**</code> matches zero or more packages </li>
1212
</ul>
1313
<p>Examples:</p>
1414
<ul>
15-
<li> <code>java.fwk.AbstractFwkClass</code> will stop count when AbstractFwkClassclass is reached. </li>
16-
<li> <code>java.fwk.*</code> will stop count when any member of java.fwkPackage package is reached. </li>
17-
<li> <code>java.fwk.**</code> same as above, but including sub-packages. </li>
15+
<li> <code>java.fwk.AbstractFwkClass</code>: the count stops when AbstractFwkClass class is reached. </li>
16+
<li> <code>java.fwk.*</code>: any member of java.fwkPackage package is reached. </li>
17+
<li> <code>java.fwk.**</code>: same as above, but including sub-packages. </li>
1818
</ul>
19-
<p>Exceptions:</p>
19+
<h2>Exceptions:</h2>
2020
<p>The rule stops counting when it encounters a class from one of the following packages (or sub-packages):</p>
2121
<ul>
2222
<li> <code>android.**</code> </li>
@@ -26,4 +26,8 @@ <h2>Why is this an issue?</h2>
2626
<li> <code>org.eclipse.**</code> </li>
2727
<li> <code>org.springframework.**</code> </li>
2828
</ul>
29+
<h2>Resources</h2>
30+
<h3>Documentation</h3>
31+
<p><a href="https://en.wikipedia.org/wiki/Composition_over_inheritance">Composition over inheritance: difference between composition and inheritance
32+
in object-oriented programming</a></p>
2933

java-checks/src/main/resources/org/sonar/l10n/java/rules/java/S1111.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<h2>Why is this an issue?</h2>
2-
<p>According to the official javadoc documentation, this Object.finalize() is called by the garbage collector on an object when garbage collection
3-
determines that there are no more references to the object. Calling this method explicitly breaks this contract and so is misleading.</p>
2+
<p>Before it reclaims storage from an object that is no longer referenced, the garbage collector calls <code>finalize()</code> on the object.</p>
3+
<p>This is a good time to release resources held by the object.</p>
4+
<p>Because the general contract is that the <code>finalize</code> method should only be called once per object, calling this method explicitly is
5+
misleading and does not respect this contract.</p>
6+
<h3>What is the potential impact?</h3>
7+
<p>An explicit call to an object’s finalize method will perform operations that most likely were supposed to be performed only when the object was not
8+
referenced anymore by any thread.</p>
9+
<p>Since it is an acceptable practice to override the finalize method in any subclass of <code>Object</code>, by invoking it explicitly, we will run
10+
code that was designed to only be ran at a different time.</p>
411
<h3>Noncompliant code example</h3>
512
<pre>
613
public void dispose() throws Throwable {
@@ -9,6 +16,7 @@ <h3>Noncompliant code example</h3>
916
</pre>
1017
<h2>Resources</h2>
1118
<ul>
19+
<li> <a href="https://docs.oracle.com/javase/specs/jls/se17/html/jls-12.html#jls-12.6">docs.oracle.com</a> - Finalization of Class Instances </li>
1220
<li> <a href="https://cwe.mitre.org/data/definitions/586">MITRE, CWE-586</a> - Explicit Call to Finalize() </li>
1321
<li> <a href="https://wiki.sei.cmu.edu/confluence/x/4jZGBQ">CERT, MET12-J.</a> - Do not use finalizers </li>
1422
</ul>

0 commit comments

Comments
 (0)