Common static analysis issues
Recipe ID
org.openrewrite.staticanalysis.CommonStaticAnalysisArtifactorg.openrewrite.recipe:rewrite-static-analysisResolve common static analysis issues (also known as SAST issues).
Composite recipeMSAL
Add to your build
Get a download tokenThis recipe is Moderne licensed, so the token must belong to a Moderne customer. It replaces YOUR_DOWNLOAD_TOKEN below.
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.staticanalysis.CommonStaticAnalysis")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.44.0")
}
Then run
./gradlew rewriteRunUsage
This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.staticanalysis.CommonStaticAnalysisIf the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-static-analysis:RELEASEDefinition
This recipe runs the following recipes in order.
- Constructors of an
abstractclass should not be declaredpublicorg.openrewrite.staticanalysis.AbstractClassPublicConstructor - Atomic Boolean, Integer, and Long equality checks compare their values
org.openrewrite.staticanalysis.AtomicPrimitiveEqualsUsesGet new BigDecimal(double)should not be usedorg.openrewrite.staticanalysis.BigDecimalDoubleConstructorRecipeBigDecimalrounding constants toRoundingModeenumsorg.openrewrite.staticanalysis.BigDecimalRoundingConstantsToEnums- Boolean checks should not be inverted
org.openrewrite.staticanalysis.BooleanChecksNotInverted - CaseInsensitive comparisons do not alter case
org.openrewrite.staticanalysis.CaseInsensitiveComparisonsDoNotChangeCase - Catch clause should do more than just rethrow
org.openrewrite.staticanalysis.CatchClauseOnlyRethrows - Chain
StringBuilder.append()callsorg.openrewrite.staticanalysis.ChainStringBuilderAppendCalls - 'Collection.toArray()' should be passed an array of the proper type
org.openrewrite.staticanalysis.CollectionToArrayShouldHaveProperType - Covariant equals
org.openrewrite.staticanalysis.CovariantEquals - Default comes last
org.openrewrite.staticanalysis.DefaultComesLast - Remove empty blocks
org.openrewrite.staticanalysis.EmptyBlock - Equals avoids null
org.openrewrite.staticanalysis.EqualsAvoidsNull - Explicit initialization
org.openrewrite.staticanalysis.ExplicitInitialization Externalizableclasses have no-arguments constructororg.openrewrite.staticanalysis.ExternalizableHasNoArgsConstructor- Finalize private fields
org.openrewrite.staticanalysis.FinalizePrivateFields - Fall through
org.openrewrite.staticanalysis.FallThrough - Finalize classes with private constructors
org.openrewrite.staticanalysis.FinalClass - Fix
String#formatandString#formattedexpressionsorg.openrewrite.staticanalysis.FixStringFormatExpressions forloop counters incremented in updateorg.openrewrite.staticanalysis.ForLoopIncrementInUpdate- Use
indexOf(String, int)org.openrewrite.staticanalysis.IndexOfChecksShouldUseAStartPosition indexOf()replaceable bycontains()org.openrewrite.staticanalysis.IndexOfReplaceableByContainsindexOfshould not compare greater than zeroorg.openrewrite.staticanalysis.IndexOfShouldNotCompareGreaterThanZero- Inline variable
org.openrewrite.staticanalysis.InlineVariable - Use
Collection#isEmpty()instead of comparingsize()org.openrewrite.staticanalysis.IsEmptyCallOnCollections - Simplify lambda blocks to expressions
org.openrewrite.staticanalysis.LambdaBlockToExpression - Standardize method name casing
org.openrewrite.staticanalysis.MethodNameCasing switchstatements should have at least 3caseclausesorg.openrewrite.staticanalysis.MinimumSwitchCases- Modifier order
org.openrewrite.staticanalysis.ModifierOrder - No multiple variable declarations
org.openrewrite.staticanalysis.MultipleVariableDeclarations - Fix missing braces
org.openrewrite.staticanalysis.NeedBraces - Nested enums are not static
org.openrewrite.staticanalysis.NestedEnumsAreNotStatic - Change
StringBuilderandStringBuffercharacter constructor argument toStringorg.openrewrite.staticanalysis.NewStringBuilderBufferWithCharArgument - No double brace initialization
org.openrewrite.staticanalysis.NoDoubleBraceInitialization - Use
Collections#emptyList(),emptyMap(), andemptySet()org.openrewrite.staticanalysis.NoEmptyCollectionWithRawType - Use comparison rather than equality checks in for conditions
org.openrewrite.staticanalysis.NoEqualityInForCondition - Remove
finalize()methodorg.openrewrite.staticanalysis.NoFinalizer - No primitive wrappers for #toString() or #compareTo(..)
org.openrewrite.staticanalysis.NoPrimitiveWrappersForToStringOrCompareTo - Jump statements should not be redundant
org.openrewrite.staticanalysis.NoRedundantJumpStatements - Unnecessary
String#toStringorg.openrewrite.staticanalysis.NoToStringOnStringType - Unnecessary
String#valueOf(..)org.openrewrite.staticanalysis.NoValueOfOnStringType finalize()calls superorg.openrewrite.staticanalysis.ObjectFinalizeCallsSuper- Prefer
System.getProperty("user.home")overSystem.getenv("HOME")org.openrewrite.staticanalysis.PreferSystemGetPropertyOverGetenv - Use primitive wrapper
valueOfmethodorg.openrewrite.staticanalysis.PrimitiveWrapperClassConstructorToValueOf - Redundant file creation
org.openrewrite.staticanalysis.RedundantFileCreation - Remove extra semicolons
org.openrewrite.staticanalysis.RemoveExtraSemicolons - Remove no argument
super()constructor callsorg.openrewrite.staticanalysis.RemoveNoArgumentSuperConstructorCall - Remove redundant null checks before instanceof
org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeInstanceof - Remove redundant null checks before literal equals
org.openrewrite.staticanalysis.RemoveRedundantNullCheckBeforeLiteralEquals - Rename methods named
hashcode,equal, ortostringorg.openrewrite.staticanalysis.RenameMethodsNamedHashcodeEqualOrToString - Replace
A.class.isInstance(a)witha instanceof Aorg.openrewrite.staticanalysis.ReplaceClassIsInstanceWithInstanceof - Use method references in lambda
org.openrewrite.staticanalysis.ReplaceLambdaWithMethodReference - Replace
StringBuilder#appendwithStringorg.openrewrite.staticanalysis.ReplaceStringBuilderWithString - Replace String concatenation with
String.valueOf()org.openrewrite.staticanalysis.ReplaceStringConcatenationWithStringValueOf - Simplify
Arrays.asList(..)with varargsorg.openrewrite.staticanalysis.SimplifyArraysAsList - Simplify boolean expression
org.openrewrite.staticanalysis.SimplifyBooleanExpression - Simplify boolean return
org.openrewrite.staticanalysis.SimplifyBooleanReturn - Static methods need not be final
org.openrewrite.staticanalysis.StaticMethodNotFinal - Use
String.equals()onStringliteralsorg.openrewrite.staticanalysis.StringLiteralEquality - Unnecessary close in try-with-resources
org.openrewrite.staticanalysis.UnnecessaryCloseInTryWithResources - Unnecessary explicit type arguments
org.openrewrite.staticanalysis.UnnecessaryExplicitTypeArguments - Remove unnecessary parentheses
org.openrewrite.staticanalysis.UnnecessaryParentheses - Remove
@Nullableand@CheckForNullannotations from primitivesorg.openrewrite.staticanalysis.UnnecessaryPrimitiveAnnotations - Unnecessary
returnas last statement in void methodorg.openrewrite.staticanalysis.UnnecessaryReturnAsLastStatement - Upper case literal suffixes
org.openrewrite.staticanalysis.UpperCaseLiteralSuffixes - Use the diamond operator
org.openrewrite.staticanalysis.UseDiamondOperator - No C-style array declarations
org.openrewrite.staticanalysis.UseJavaStyleArrayDeclarations - Use %n instead of \n in format strings
org.openrewrite.staticanalysis.UsePortableNewlines - Prefer
whileoverforloopsorg.openrewrite.staticanalysis.WhileInsteadOfFor - Write octal values as decimal
org.openrewrite.staticanalysis.WriteOctalValuesAsDecimal - Structural equality tests should use
==or!=org.openrewrite.kotlin.cleanup.EqualsMethodUsage itshouldn't be used as a lambda parameter nameorg.openrewrite.kotlin.cleanup.ImplicitParameterInLambda- Replace
Char#toInt()withChar#codeorg.openrewrite.kotlin.cleanup.ReplaceCharToIntWithCode - Order imports
org.openrewrite.java.OrderImports
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats