Common static analysis issues
MSALResolve common static analysis issues (also known as SAST issues).
org. openrewrite. staticanalysis. CommonStaticAnalysismod run . --recipe= org. openrewrite. staticanalysis. CommonStaticAnalysisInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.
Recipe list
It runs these recipes, in this order.
- Constructors of an
abstractclass should not be declaredpublic AtomicBoolean,AtomicInteger, andAtomicLongequality checks compare their valuesBigDecimalrounding constants toRoundingModeenums- Boolean checks should not be inverted
- Case-insensitive comparisons do not alter case
- Catch clause should do more than just rethrow
- Chain
StringBuilder.append()calls Collection.toArray()should be passed an array of the proper type- Covariant equals
- Default comes last
- Remove empty blocks
- Equals avoids null
- Explicit initialization
Externalizableclasses have no-arguments constructor- Finalize private fields
- Finalize classes with private constructors
- Fix
String#formatandString#formattedexpressions forloop counters incremented in update- Use
indexOf(String, int) indexOf()replaceable bycontains()indexOfshould not compare greater than zero- Inline variable
- Use
Collection#isEmpty()instead of comparingsize() - Use
Map#isEmpty()instead of comparingsize() - Simplify lambda blocks to expressions
switchstatements should have at least 3caseclauses- Modifier order
- No multiple variable declarations
- Fix missing braces
- Nested enums are not static
- Change
StringBuilderandStringBuffercharacter constructor argument toString - No double brace initialization
- Use
Collections#emptyList(),emptyMap(), andemptySet() - Use comparison rather than equality checks in for conditions
- No primitive wrappers for
#toString()or#compareTo(..) - Jump statements should not be redundant
- Unnecessary
String#toString - Unnecessary
String#valueOf(..) finalize()calls super- Prefer
System.getProperty(..)overSystem.getenv(..) - Use primitive wrapper
valueOfmethod - Redundant
Filecreation - Remove extra semicolons
- Remove no argument
super()constructor calls - Remove redundant null checks before
instanceof - Remove redundant null checks before literal equals
- Rename methods named
hashcode,equal, ortostring - Replace
A.class.isInstance(a)witha instanceof A - Use method references in lambda
- Replace
StringBuilder#appendwithString - Replace
Stringconcatenation withString.valueOf() - Simplify
Arrays.asList(..)with varargs - Simplify boolean expression
- Simplify boolean return
- Static methods need not be final
- Use
String.equals()onStringliterals - Unnecessary close in try-with-resources
- Unnecessary explicit type arguments
- Remove unnecessary parentheses
- Remove
@Nullableand@CheckForNullannotations from primitives - Unnecessary
returnas last statement in void method - Upper case literal suffixes
- Use the diamond operator
- No C-style array declarations
- Use
%ninstead of\nin format strings - Prefer
whileoverforloops - Write octal values as decimal
- Structural equality tests should use
==or!= itshouldn't be used as a lambda parameter name- Replace
Char#toInt()withChar#code - Order imports