From 15ceb9fff0620cecf904442ff3901eab5776d495 Mon Sep 17 00:00:00 2001 From: Chester Date: Tue, 27 Feb 2018 18:24:03 +0800 Subject: [PATCH] add set rule set --- .../resources/com/sonar/sqale/pmd-model.xml | 80 +++++++++++++++++++ .../resources/org/sonar/l10n/pmd.properties | 10 ++- ...stExceptionWithSubListToArrayListRule.html | 12 +++ .../ClassCastExceptionWithToArrayRule.html | 9 +++ ...ollectionInitShouldAssignCapacityRule.html | 9 +++ ...tExceptionWithModifyOriginSubListRule.html | 10 +++ .../DontModifyInForeachCircleRule.html | 20 +++++ ...upportedExceptionWithModifyAsListRule.html | 13 +++ .../org/sonar/plugins/pmd/rules-p3c.xml | 34 +++++++- 9 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithSubListToArrayListRule.html create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithToArrayRule.html create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CollectionInitShouldAssignCapacityRule.html create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConcurrentExceptionWithModifyOriginSubListRule.html create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/DontModifyInForeachCircleRule.html create mode 100644 src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UnsupportedExceptionWithModifyAsListRule.html diff --git a/src/main/resources/com/sonar/sqale/pmd-model.xml b/src/main/resources/com/sonar/sqale/pmd-model.xml index 4fc6478..66b26f0 100644 --- a/src/main/resources/com/sonar/sqale/pmd-model.xml +++ b/src/main/resources/com/sonar/sqale/pmd-model.xml @@ -4507,6 +4507,86 @@ min + + + + pmd + ClassCastExceptionWithToArrayRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + + + pmd + UnsupportedExceptionWithModifyAsListRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + + + pmd + ClassCastExceptionWithSubListToArrayListRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + + + pmd + ConcurrentExceptionWithModifyOriginSubListRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + + + pmd + DontModifyInForeachCircleRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + + + pmd + CollectionInitShouldAssignCapacityRule + + remediationFunction + CONSTANT_ISSUE + + + offset + 2 + min + + diff --git a/src/main/resources/org/sonar/l10n/pmd.properties b/src/main/resources/org/sonar/l10n/pmd.properties index 10d7bf1..474f453 100644 --- a/src/main/resources/org/sonar/l10n/pmd.properties +++ b/src/main/resources/org/sonar/l10n/pmd.properties @@ -417,4 +417,12 @@ rule.pmd.StringConcatRule.name=[p3c]Use the append method in StringBuilder insid rule.pmd.AvoidPatternCompileInMethodRule.name=[p3c]When using regex, precompile needs to be done in order to increase the matching performance. rule.pmd.AvoidApacheBeanUtilsCopyRule.name=[p3c]Avoid using *Apache Beanutils* to copy attributes. rule.pmd.AvoidNewDateGetTimeRule.name=[p3c]Use System.currentTimeMillis() to get the current millisecond. Do not use new Date().getTime(). -rule.pmd.AvoidMissUseOfMathRandomRule.name=[p3c]The return type of Math.random() is double, value range is 0<=x<1 (0 is possible). \ No newline at end of file +rule.pmd.AvoidMissUseOfMathRandomRule.name=[p3c]The return type of Math.random() is double, value range is 0<=x<1 (0 is possible). + +#AlibabaJavaSets +rule.pmd.ClassCastExceptionWithToArrayRule.name=[p3c]Do not use toArray method without arguments. +rule.pmd.UnsupportedExceptionWithModifyAsListRule.name=[p3c]Do not use methods which will modify the list after using Arrays.asList to convert array to list. +rule.pmd.ClassCastExceptionWithSubListToArrayListRule.name=[p3c]Do not cast subList in class ArrayList, otherwise ClassCastException will be thrown. +rule.pmd.ConcurrentExceptionWithModifyOriginSubListRule.name=[p3c]When using subList, be careful to modify the size of original list. +rule.pmd.DontModifyInForeachCircleRule.name=[p3c]Do not remove or add elements to a collection in a foreach loop. +rule.pmd.CollectionInitShouldAssignCapacityRule.name=[p3c]HashMap should set a size when initializing. \ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithSubListToArrayListRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithSubListToArrayListRule.html new file mode 100644 index 0000000..80d090f --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithSubListToArrayListRule.html @@ -0,0 +1,12 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Negative example:
+    List list = new ArrayList();
+    list.add("22");
+    //warn
+    List test = (ArrayList) list.subList(0, 1);
+
+    Positive example:
+    List list2 = new ArrayList(list.subList(0, 1));
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithToArrayRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithToArrayRule.html new file mode 100644 index 0000000..5a96cf8 --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ClassCastExceptionWithToArrayRule.html @@ -0,0 +1,9 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Negative example:
+    Integer[] a = (Integer [])c.toArray();
+
+    Positive example:
+    Integer[] b = (Integer [])c.toArray(new Integer[c.size()]);
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CollectionInitShouldAssignCapacityRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CollectionInitShouldAssignCapacityRule.html new file mode 100644 index 0000000..5210e97 --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/CollectionInitShouldAssignCapacityRule.html @@ -0,0 +1,9 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Negative example:
+    Map map = new HashMap();
+
+    Positive example:
+    Map map = new HashMap(16);
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConcurrentExceptionWithModifyOriginSubListRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConcurrentExceptionWithModifyOriginSubListRule.html new file mode 100644 index 0000000..bf8151a --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/ConcurrentExceptionWithModifyOriginSubListRule.html @@ -0,0 +1,10 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Negative example:
+    List originList = new ArrayList();
+    originList.add("22");
+    List subList = originList.subList(0, 1);
+    //warn
+    originList.add("22");
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/DontModifyInForeachCircleRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/DontModifyInForeachCircleRule.html new file mode 100644 index 0000000..c002874 --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/DontModifyInForeachCircleRule.html @@ -0,0 +1,20 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Negative example:
+    List originList = new ArrayList();
+    originList.add("22");
+    for (String item : originList) {
+      //warn
+      list.add("bb");
+    }
+
+    Positive example:
+    Iterator it=b.iterator();
+    while(it.hasNext()){
+    Integer temp =  it.next();
+        if (delCondition) {
+          it.remove();
+        }
+    }
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UnsupportedExceptionWithModifyAsListRule.html b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UnsupportedExceptionWithModifyAsListRule.html new file mode 100644 index 0000000..6fb0815 --- /dev/null +++ b/src/main/resources/org/sonar/l10n/pmd/rules/pmd-p3c/UnsupportedExceptionWithModifyAsListRule.html @@ -0,0 +1,13 @@ +

Look for qualified this usages in the same class.

+

Examples:

+
+    Positive example:
+    List t   = Arrays.asList("a","b","c");
+    //warn
+    t.add("22");
+    //warn
+    t.remove("22");
+    //warn
+    t.clear();
+
+
\ No newline at end of file diff --git a/src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml b/src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml index 3572a2c..3a02b70 100644 --- a/src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml +++ b/src/main/resources/org/sonar/plugins/pmd/rules-p3c.xml @@ -169,19 +169,45 @@ - CRITICAL + BLOCKER - CRITICAL + BLOCKER - CRITICAL + BLOCKER - CRITICAL + MAJOR + + + + CRITICAL + + + + CRITICAL + + + + CRITICAL + + + + CRITICAL + + + + BLOCKER + + + + MAJOR + +