New features.

This commit is contained in:
Kui LIU
2017-11-06 20:10:17 +01:00
parent 1218230723
commit c695159c38
22 changed files with 843 additions and 3162 deletions
+119
View File
@@ -0,0 +1,119 @@
BC_UNCONFIRMED_CAST
BC_UNCONFIRMED_CAST_OF_RETURN_VALUE Comments: no any useful common fix patterns.
EI_EXPOSE_REP
EI_EXPOSE_REP2
IS2_INCONSISTENT_SYNC
NM_METHOD_NAMING_CONVENTION
DE_MIGHT_IGNORE Compile failed.
DLS_DEAD_LOCAL_STORE Compile failed
NP_LOAD_OF_KNOWN_NULL_VALUE
DM_CONVERT_CASE To be improved
DM_BOXED_PRIMITIVE_FOR_PARSING
DM_DEFAULT_ENCODING
DM_FP_NUMBER_CTOR
DM_NUMBER_CTOR
ES_COMPARING_STRINGS_WITH_EQ Comments: ignored
MS_PKGPROTECT
MS_SHOULD_BE_FINAL Comments: failed to checkstyle.
NP_NONNULL_RETURN_VIOLATION
NP_NULL_ON_SOME_PATH
NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE
OBL_UNSATISFIED_OBLIGATION
OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE
ODR_OPEN_DATABASE_RESOURCE
OS_OPEN_STREAM
OS_OPEN_STREAM_EXCEPTION_PATH
PZLA_PREFER_ZERO_LENGTH_ARRAYS
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE
REC_CATCH_EXCEPTION
RI_REDUNDANT_INTERFACES
RV_RETURN_VALUE_IGNORED_BAD_PRACTICE
RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT
SBSC_USE_STRINGBUFFER_CONCATENATION
SE_NO_SERIALVERSIONID
SF_SWITCH_NO_DEFAULT
SIC_INNER_SHOULD_BE_STATIC
SIC_INNER_SHOULD_BE_STATIC_ANON
SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING
ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD
UC_USELESS_CONDITION
UC_USELESS_OBJECT
UCF_USELESS_CONTROL_FLOW
UPM_UNCALLED_PRIVATE_METHOD
URF_UNREAD_FIELD
URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD
UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
UWF_UNWRITTEN_FIELD
VA_FORMAT_STRING_USES_NEWLINE
WMI_WRONG_MAP_ITERATOR
rejected 1 https://github.com/apache/commons-io/pull/47
rejected 1 https://github.com/apache/commons-io/pull/45
rejected 1 https://github.com/apache/commons-lang/pull/298
5 https://github.com/apache/commons-lang/pull/297
improved 1 https://github.com/apache/commons-lang/pull/297 Comments: some patches failed to pass test cases, some patches led to compile failed, some patches led to checkstyle failed.
2 https://github.com/apache/commons-math/pull/69
1 https://github.com/apache/commons-math/pull/68 Comments: inner static class, there is no need to fix the violations in this kind of class.
2 https://github.com/apache/commons-math/pull/67 Comments: improve patches.
1 https://github.com/apache/commons-math/pull/66
rejected 1 https://github.com/apache/ant/pull/47
improved 1 https://github.com/apache/ant/pull/46
merged 2 https://github.com/apache/ant/pull/46
2 https://github.com/apache/ant/pull/45
rejected 3 https://github.com/apache/ant/pull/44
merged 1 https://github.com/apache/ant/pull/43
merged 5 https://github.com/apache/ant/pull/42 Comments: need to import new packages, unless the fixed patches will fail to compile.
merged 1 https://github.com/apache/ant/pull/41
1 https://github.com/apache/aries/pull/80
1 https://github.com/apache/aries/pull/79
1 https://github.com/apache/aries/pull/78
1 https://github.com/apache/aries/pull/77
1 https://github.com/apache/aries/pull/76
rejected 1 https://github.com/apache/camel/pull/2031 ShouldBeFinal
rejected 6 https://github.com/apache/camel/pull/2029 master5
merged 1 https://github.com/apache/camel/pull/2035 master7
merged 2 https://github.com/apache/camel/pull/2032 Useless
merged 2 https://github.com/apache/camel/pull/2025 master6
merged 1 https://github.com/apache/camel/pull/2024 master4
merged 1 https://github.com/apache/camel/pull/2023 master2
rejected 1 https://github.com/apache/camel/pull/2017 master3 Comments: compile failed, the return value of method invocation is not Boolean, it is a specific case.
merged 1 https://github.com/apache/camel/pull/2016 master
merged 6 https://github.com/apache/camel/pull/2038 boxedParsing
3 https://github.com/apache/cassandra/pull/165
4 https://github.com/apache/cassandra/pull/164
2 https://github.com/apache/cassandra/pull/163
Fixed 1 https://github.com/fangyidong/json-simple/pull/126 Comments: fixed in another version. https://github.com/RalleYTN/SimpleJSON
1 https://github.com/fangyidong/json-simple/pull/125
On hold 1 https://github.com/apache/mahout/pull/346
1 https://github.com/apache/mahout/pull/345
1 https://github.com/apache/mahout/pull/344
merged 2 https://github.com/apache/poi/pull/77 5
merged 4 https://github.com/apache/poi/pull/78 6
merged 2 https://github.com/apache/poi/pull/79 t
merged 1 https://github.com/apache/poi/pull/80 4
merged 4 https://github.com/apache/poi/pull/76 2
merged 30 https://github.com/apache/poi/pull/75 master
merged 1 https://github.com/apache/poi/pull/74 3
Some violations never happened in these projects:
+131
View File
@@ -0,0 +1,131 @@
=====================================
=========Useful Fix Patterns=========
=====================================
==============Detailed===============
DM_CONVERT_CASE
(1) ADD a rule of Locale.ENGLISH into toLowerCase/toUpperCase.
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE
(1) DEL Null-Check IfStatement,
(2) DEL Null-Check Conditional Expression.
REC_CATCH_EXCEPTION
(1) Change Exception to a specific exception class.
SE_NO_SERIALVERSIONID
(1) Insert a private static final field serialVersionUID.
VA_FORMAT_STRING_USES_NEWLINE
(1) DEL "$backslash$n",
(2) Replace "$backslash$n" with "n"
MS_SHOULD_BE_FINAL
(1) ADD a ``final'' modifier.
WMI_WRONG_MAP_ITERATOR
(1) Replace the KeySet iterating ForStatement with an EntrySet iterating ForStatement.
DM_NUMBER_CTOR
(1) Replace the NumberType ClassInstanceCreation with a NumberType.valueOf() method invocation.
SIC_INNER_SHOULD_BE_STATIC
(1) ADD a "static" modifier,
(2) DEL the buggy statements.
DE_MIGHT_IGNORE
(1) Change Exception to a specific exception class.
DM_BOXED_PRIMITIVE_FOR_PARSING
(1) Replace NumberType.valueOf() with NumberType.parseNumberType().
DM_FP_NUMBER_CTOR
(1) DEL the buggy statement,
(2) Replace Double or Float ClassInstanceCreation with (Double or Float).valueOf(),
(3) Remove the Double or Float ClassInstanceCreation from the buggy expression.
MS_PKGPROTECT
(1) DEL the buggy statement,
(2) DEL the ``public'' or ``protected'' modifier
(3) Replace the ``public'' or ``protected'' modifier with the ``private'' modifier.
(4) DEL the initialization expression.
ES_COMPARING_STRINGS_WITH_EQ
(1) Replace the ``=='' InfixExpression with a stringVar.equals() method invocation.
===============Abstract==============
NP_NULL_ON_SOME_PATH
(1) ADD a Null-check statement or expression.
RI_REDUNDANT_INTERFACES
(1) DEL the implemented Interface type.
NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE
(1) ADD a Null-check statement or expression,
(2) DEL the buggy statement.
UCF_USELESS_CONTROL_FLOW
(1) DEL the buggy statement,
(2) DEL the useless ConditionalExpression.
UC_USELESS_CONDITION
(1) UPD the operator of a ConditionalExpersion,
(2) UPD an sub-expression of a ConditionExpression.
NP_LOAD_OF_KNOWN_NULL_VALUE
(1) DEL Null-check expression or statement,
(2) Replace the null-known variable with NULL.
SBSC_USE_STRINGBUFFER_CONCATENATION
(1) Replace String type with StringBuilder, and replace plus operator of StringVarialbe with the append method of StringBuilder.
UC_USELESS_OBJECT
(1) DEL the buggy statement.
UPM_UNCALLED_PRIVATE_METHOD
(1) DEL the buggy statements.
NM_METHOD_NAMING_CONVENTION
(1) Update Method Name of MethodDeclaration.
URF_UNREAD_FIELD
(1) DEL the buggy statement.
=====================================
NP_NONNULL_RETURN_VIOLATION
(1) DEL the null-returned ReturnStatement.
(2) Replace NullLiteral with an Expression which returns an empty list.
PZLA_PREFER_ZERO_LENGTH_ARRAYS
(1) DEL the buggy statement,
√ (2) Replace NullLiteral with an empty array.
SIC_INNER_SHOULD_BE_STATIC_ANON
(1) DEL a parameter of a ClassInstanceCreation in an AnonymousClassDeclaration,
(2) DEL the statement contains an AnonymousClassDeclaration,
√ (3) Replace the AnonymousClassDeclaration with an defined Static Object of this class.
DLS_DEAD_LOCAL_STORE
(1) DEL the buggy statement.
DM_DEFAULT_ENCODING
√ (1) ADD a parameter (i.e., "UTF-8") into the ClassInstanceCreation of a Stream object.
(2) Replace ClassInstanceCreation with a MethodInvocation.
(3) DEL the buggy statement.
BC_UNCONFIRMED_CAST
(1) DEL the buggy statement,
(2) DEL the Cast Type,
(3) Replace CastExpression with NullLiteral.
URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD
(1) ADD a ``final'' modifier,
√ (2) DEL the buggy statement.
RV_RETURN_VALUE_IGNORED_BAD_PRACTICE
(1) Replace boolean-returned statement with a a new MethodInvocation.
√ (2) ADD an IfStatement.
EI_EXPOSE_REP
(1) DEL the buggy statement,
* (2) Replace the being assigned Expression with a ConditionalExpression.
√ (3) Replace the Expression being assigned with other Expression
EI_EXPOSE_REP2
(1) DEL the buggy statement,
* (2) Replace the being assigned Expression with a ConditionalExpression.
√ (3) Replace the being assigned Expression with other Expression.
=====================================
==========Null Fix Patterns==========
=====================================
UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR null.
OBL_UNSATISFIED_OBLIGATION null.
OS_OPEN_STREAM_EXCEPTION_PATH null.
SF_SWITCH_NO_DEFAULT null.
UWF_UNWRITTEN_FIELD null.
IS2_INCONSISTENT_SYNC null.
ODR_OPEN_DATABASE_RESOURCE null.
SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING null.
OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE null.
OS_OPEN_STREAM null.
NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE null.
=====================================
========Useless Fix Patterns=========
=====================================
BC_UNCONFIRMED_CAST_OF_RETURN_VALUE
(1) UPD T1 v1 = (T1) method_invocation() with T2 v1 = method_invocation(),
(2) DEL the buggy statement,
(3) Replace the buggy CastExpresion with a MethodInvocation.
ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD
(1) DEL the buggy statement.
RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE
(1) ADD a Null-check statement or expression.
@@ -0,0 +1,107 @@
================================
=========Single Pattern=========
================================
SIC_INNER_SHOULD_BE_STATIC_ANON: new Type() { override some methods(...){...} }. Anonymous inner class declaration. 100%
DE_MIGHT_IGNORE: try{...} catch (Exception e) {...}, Exception is not any specified.
VA_FORMAT_STRING_USES_NEWLINE: "\n", this new line symbol is in a StringLiteral of a format method.
UCF_USELESS_CONTROL_FLOW: if (conditional expression) {empty statements.}.
UC_USELESS_CONDITION: if (conditional expressions) {...}.
UC_USELESS_OBJECT: T1 v1 = new T1().
PZLA_PREFER_ZERO_LENGTH_ARRAYS: return null.
EI_EXPOSE_REP: return variable;
REC_CATCH_EXCEPTION: try{...} catch (Exception e) {...}, Exception is not any specific exception.
SF_SWITCH_NO_DEFAULT: switch(exp) {case1:...case2:...}, without default statement.
UWF_UNWRITTEN_FIELD: return exp / variable.
SBSC_USE_STRINGBUFFER_CONCATENATION: stringVariable += stringExp,
RV_RETURN_VALUE_IGNORED_NO_SIDE_EFFECT: return method_invocation_exp. Method invocation statement returns a value, but does not assign the value to any variable. (High false positives.)
NP_NONNULL_RETURN_VIOLATION: return null. (High false positives.)
================================
========Multiple Patterns=======
================================
NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: (1) for (File file : filesArray) {...} (2) for (int i =0; i < filesArray.length; i ++) {...}
DM_CONVERT_CASE: (1) stringExp.toLowerCase(), 24,897
(2)stringExp.toUpperCase(). 10,406
MS_PKGPROTECT: (1) public static final T1 v1 = initializationExp, 2442
(2) protected static final T1 v1 = initializationExp. 175
(3) protected static T1 v1 = initializationExp. 158
(4) public static T1 v1 = initializationExp. 262, other 46
SIC_INNER_SHOULD_BE_STATIC: (1) this.v1 = v2; 590
(2) v1 = v2; 170
(3) super(...). 213
BC_UNCONFIRMED_CAST: (1) T1 v1 = (T(1) v2/exp, (2) v1 = (T(1) v2/exp, (3) ((T(1) v2).exp.
ES_COMPARING_STRINGS_WITH_EQ: (1) stringExp1 == stringExp2 IfStatement, ReturnStatement, WhileStatement.
(2) stringExp1 != stringExp2
RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE: (1) if (exp == null ...) {...},
(2) if (exp != null ...) {...},
(3) exp == null ? exp1 : exp2,
(4) exp != null ? exp1 : exp2.
DM_NUMBER_CTOR: (1) new Long(...), (2)new Integer(...), (3)new Short(...), (4)new Byte(...), (5)new Char(...).
DM_FP_NUMBER_CTOR: (1) new Double(exp), (2)new Float(exp).
DM_BOXED_PRIMITIVE_FOR_PARSING: (1) Integer.valueOf(str), (2)Long.valueOf(str). Comments: it contains fewer patterns than findbugs.
EI_EXPOSE_REP2: (1) this.v1 = v2,
(2) v1 = v2. 3700
BC_UNCONFIRMED_CAST_OF_RETURN_VALUE: (1) T1 v1 = (T) method_invocation(),
(2) v1 = (T) method_invocation(),
(3) ((T) method_invocation()).exp.
ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD: (1) static_v1 = instance_exp1.method_invocation(),
(2) v1 = instance_exp1.method_invocation(),
(3) v1 = exp1, other variable assignment statement.
RV_RETURN_VALUE_IGNORED_BAD_PRACTICE: (1) File.mkdirs(),
(2) File.mkdir(),
(3) File.delete(),
(4) File.createNewFile(),
(5) other exp.method_invoation() returns a value.
SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING: (1) sqlExecutionStatement = StringLiteral1 + stringV1 + ... + StringLiteral2 + stringV2.
(2) sqlRelatedVariable = sqlRelatedMethodInvocation();
OS_OPEN_STREAM: (1) StreamType v = new StreamType(...), 2) streamVariable = new StreamType(new StreamType2(...)), e.g., 1. FileOutputStream fos = new FileOutputStream(outFile);
DM_DEFAULT_ENCODING: (1) new BufferedReader(new InputStreamReader(input)), 99+
(2) new StreamWriter(output);
(3) stringExp.getBytes(),
(4) new String(byteExp),
(5) byteExp.toString().
ODR_OPEN_DATABASE_RESOURCE: (1) conn.createStatement(),
(2) conn.createStatement.execute(...),
(3) PreparedStatement st = conn.prepareStatement(),
(4) DataBaseConnection conn = exp.getConnection(...).
NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE: (1) return method_invocation(...), 2) return class_instance_creation(...).
========================================
==========Inefficient Patterns==========
========================================
OBL_UNSATISFIED_OBLIGATION: (1) StreamType v = new StreamType(...),
(2) streamVariable = new StreamType(new StreamType2(...)),
(3) sqlStatementExp.executeMethod(). e.g., 1. FileOutputStream fos = new FileOutputStream(outFile); 2. ResultSet rs = sqlStmt.executeQuery().
OS_OPEN_STREAM_EXCEPTION_PATH: (1) StreamType v = new StreamType(...),
(2) streamVariable = new StreamType(...).
IS2_INCONSISTENT_SYNC: (1) return v1,
(2) if(conditionalExp) {...},
(3) sqlStmt = stringLiteral1 + stringExp + stringLiteral2. not very consistent.
OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE: (1) StreamType v = new StreamType(...),
(2) streamVariable = new StreamType(new StreamType2(...)),
(3) sqlStatementExp.executeMethod(). e.g., 1. FileOutputStream fos = new FileOutputStream(outFile); 2. ResultSet rs = sqlStmt.executeQuery().
WMI_WRONG_MAP_ITERATOR: for statement { ... MapVariable.get(keyExp) ... }. or NULL. Lack of enough information.
========================================
=====Redundant Inconsistent Pattern=====
========================================
MS_SHOULD_BE_FINAL: (1) public (28,302) static T1 v1 = exp. e.g., public static int maxStringLength = 65535.
(2) protected (6,719) static T1 v1 = exp.
URF_UNREAD_FIELD: (1) this.v1 = v2, (2)this.v1 = new T(), (3)private Type v = exp. Comments: it contains more patterns than findbugs. only pattern 3 is consistent.
URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD: (1) this.v1 = v2,
(2) public/protected (static) T1 v1 = exp; Comments: only 2 is consistent.
(3) v1 = exp1.
========================================
=========Inconsistent Patterns=========
========================================
RI_REDUNDANT_INTERFACES: super(...). Comments: not very consistent. Locate on the position of super classes.
========================================
==============Null Pattern==============
========================================
===========Inaccurate Position==========
NM_METHOD_NAMING_CONVENTION: null. Comments: violate on title, but position locates on body.
SE_NO_SERIALVERSIONID: null.
UPM_UNCALLED_PRIVATE_METHOD: null. (method body)
UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR: null. inaccurate positions.
==========Specific Source Code==========
DLS_DEAD_LOCAL_STORE: null. Variable assignment statements. Comments: specific source code.
NP_NULL_ON_SOME_PATH: null.
NP_LOAD_OF_KNOWN_NULL_VALUE: null.
RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE: null.
-2518
View File
File diff suppressed because it is too large Load Diff