Skip to content

Commit

Permalink
Sonar integration tags, Feature Request: Add classification tags to t…
Browse files Browse the repository at this point in the history
…he rules #306
  • Loading branch information
jborgers committed May 3, 2024
1 parent b001b32 commit af6203f
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 11 deletions.
86 changes: 81 additions & 5 deletions rulesets/java/jpinpoint-rules.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/resources/category/java/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ class Foo {
<properties>
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="suspicious" type="String" description="for-sonar"/>
<property name="tag" value="data-mix-up" type="String" description="for-sonar"/>
<property name="ruleIdMatches" type="String" value="AvoidUnguardedMutableFieldsInSharedObjects|AvoidUnguardedAssignmentToNonFinalFieldsInSharedObjects|AvoidMutableStaticFields|[^\w]ALL[^\w]|[^\w]all[^\w]|PMD[^\.]|pmd[^:]"
description="Regex for inclusion of high risk rules"/>
<property name="ruleIdNotMatches" type="String" value="^$"
Expand Down
12 changes: 8 additions & 4 deletions src/main/resources/category/java/concurrent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ancestor::StatementExpression/PrimaryExpression/PrimaryPrefix/Name/@Image = ance
class="net.sourceforge.pmd.lang.rule.XPathRule" dfa="false" language="java"
typeResolution="true" externalInfoUrl="${doc_root}/JavaCodePerformance.md#tutc07">
<description>
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. Unguarded assignment to a non-final field is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mixup session data. &#13;
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. Unguarded assignment to a non-final field is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mix-up session data. &#13;
Solution: Make the fields final and unmodifiable. If they really need to be mutable, make access thread-safe: use synchronized and jcip @GuardedBy or use volatile.&#13;
Notes&#13;
1. For autowiring/injection, the assignment of the reference is thread safe, so final is not required. The unmodifiable/thread-safe requirement for that field still holds. Also make sure no other thread-unsafe assignment is made to that field.&#13;
Expand All @@ -211,6 +211,7 @@ ancestor::StatementExpression/PrimaryExpression/PrimaryPrefix/Name/@Image = ance
<properties>
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="multi-threading" type="String" description="for-sonar"/>
<property name="tag" value="data-mix-up" type="String" description="for-sonar"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
Expand Down Expand Up @@ -299,7 +300,7 @@ and not (ancestor::ClassOrInterfaceBodyDeclaration/Annotation//Name[@Image='Auto
class="net.sourceforge.pmd.lang.rule.XPathRule" dfa="false" language="java"
typeResolution="true" externalInfoUrl="${doc_root}/JavaCodePerformance.md#tutc07">
<description>
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. If a field or its reference is mutable, access is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mixup session data.&#13;
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. If a field or its reference is mutable, access is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mix-up session data.&#13;
Solution: Make the fields final and unmodifiable. If they really need to be mutable, make access thread-safe: use synchronized and jcip @GuardedBy or use volatile.&#13;
Notes&#13;
1. Instances of Date, StringBuilder, URL and File are examples of mutable objects and should be avoided (or else guarded) as fields of shared objects. In case mutable fields are final and not modified after initialization (read-only) they are thread safe, however any modification to it is thread-unsafe. Since field modification is easily coded, avoid this situation.
Expand All @@ -312,6 +313,7 @@ and not (ancestor::ClassOrInterfaceBodyDeclaration/Annotation//Name[@Image='Auto
<properties>
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="multi-threading" type="String" description="for-sonar"/>
<property name="tag" value="data-mix-up" type="String" description="for-sonar"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
Expand Down Expand Up @@ -358,7 +360,7 @@ and not (../Annotation//Name[@Image='GuardedBy'])
class="net.sourceforge.pmd.lang.rule.XPathRule" dfa="false" language="java"
typeResolution="true" externalInfoUrl="${doc_root}/JavaCodePerformance.md#tutc07">
<description>
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. If a (inherited) field or its reference is mutable, access is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mixup session data. &#13;
Problem: Multiple threads typically access fields of a singleton or may access fields in session scoped objects. If a (inherited) field or its reference is mutable, access is thread-unsafe and may cause corruption or visibility problems. It may also unintentionally mix-up session data. &#13;
Solution: Make the fields final and unmodifiable. If they really need to be mutable, make access thread-safe: use synchronized and jcip @GuardedBy or use volatile.&#13;
Notes&#13;
1. Instances of Date, StringBuilder, URL and File are examples of mutable objects and should be avoided (or else guarded) as fields of shared objects. In case mutable fields are final and not modified after initialization (read-only) they are thread safe, however any modification to it is thread-unsafe. Since field modification is easily coded, avoid this situation.
Expand All @@ -371,6 +373,7 @@ and not (../Annotation//Name[@Image='GuardedBy'])
<properties>
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="multi-threading" type="String" description="for-sonar"/>
<property name="tag" value="data-mix-up" type="String" description="for-sonar"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
Expand Down Expand Up @@ -1006,7 +1009,8 @@ public class Foo {
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="multi-threading" type="String" description="for-sonar"/>
<property name="tag" value="correctness" type="String" description="for-sonar"/>
<property name="tag" value="suspicious" type="String" description="for-sonar"/>
<property name="tag" value="suspicious" type="String" description="for-sonar"/>
<property name="tag" value="data-mix-up" type="String" description="for-sonar"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value><![CDATA[
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/category/java/enterprise.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<priority>3</priority>
<properties>
<property name="tag" value="jpinpoint-rule" type="String" description="for-sonar"/>
<property name="tag" value="confusing" type="String" description="for-sonar"/>
<property name="tag" value="multi-threading" type="String" description="for-sonar"/>
<property name="tag" value="performance" type="String" description="for-sonar"/>
<property name="version" value="2.0"/>
<property name="xpath">
<value>
Expand Down
Loading

0 comments on commit af6203f

Please sign in to comment.