facebook pixelJava Static Analysis Rules
BACK TO LIST

Java rules

The Codiga Code Analysis engine supports hundreds of rules for Java, checking that your code is safe and secure. Start using Codiga today to check your code and automate your code reviews to find issues in every pull request and merge with confidence.

      AbstractClassWithoutAbstractMethod

      Best practice
      Medium

      This abstract class does not have any abstract methods

      Learn more

      AbstractClassWithoutAnyMethod

      Design
      Critical

      No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.

      AssignmentToNonFinalStatic

      Error prone
      Medium

      Possible unsafe assignment to a non-final static field in a constructor.

      AvoidBranchingStatementAsLastInLoop

      Error prone
      High

      Avoid using a branching statement as the last in a loop.

      AvoidDecimalLiteralsInBigDecimalConstructor

      Error prone
      Medium

      Avoid creating BigDecimal with a decimal (float/double) literal. Use a String literal

      AvoidDeeplyNestedIfStmts

      Design
      Medium

      Deeply nested if..then statements are hard to read

      AvoidInstanceofChecksInCatchClause

      Error prone
      Medium

      An instanceof check is being performed on the caught exception. Create a separate catch clause for this exception type.

      AvoidMultipleUnaryOperators

      Error prone
      High

      Using multiple unary operators may be a bug

      AvoidProtectedFieldInFinalClass

      Code style
      Medium

      Avoid protected fields in a final class. Change to private or package access.

      AvoidProtectedMethodInFinalClassNotExtending

      Code style
      Medium

      Avoid protected methods in a final class that doesnt extend anything other than Object. Change to private or package access.

      AvoidReassigningParameters

      Best practice
      High

      Avoid reassigning parameters

      AvoidSynchronizedAtMethodLevel

      Unknown
      Medium

      Use block level rather than method level synchronization

      AvoidThreadGroup

      Unknown
      Medium

      Avoid using java.lang.ThreadGroup; it is not thread safe

      AvoidUsingHardCodedIP

      Best practice
      Medium

      Do not hard code the IP address

      AvoidUsingOctalValues

      Error prone
      Medium

      Do not start a literal by 0 unless its an octal value

      BadComparison

      Error prone
      Medium

      Avoid equality comparisons with Double.NaN

      BigIntegerInstantiation

      Unknown
      Medium

      Dont create instances of already existing BigInteger and BigDecimal.

      BooleanInstantiation

      Unknown
      High

      Avoid instantiating Boolean objects; reference Boolean.TRUE or Boolean.FALSE or call Boolean.valueOf() instead.

      BrokenNullCheck

      Error prone
      High

      Method call on object which may be null

      CheckResultSet

      Best practice
      Medium

      Always check the return of one of the navigation method (next

      CheckSkipResult

      Error prone
      Medium

      Check the value returned by the skip() method of an InputStream to see if the requested number of bytes has been skipped.

      ClassCastExceptionWithToArray

      Error prone
      Medium

      This usage of the Collection.toArray() method will throw a ClassCastException.

      ClassWithOnlyPrivateConstructorsShouldBeFinal

      Design
      Critical

      A class which only has private constructors should be final

      CloseResource

      Error prone
      Medium

      Ensure that resources like this PipedWriter object are closed after use

      CollapsibleIfStatements

      Design
      Medium

      These nested if statements could be combined

      CompareObjectsWithEquals

      Error prone
      Medium

      Use equals() to compare object references.

      ConfusingTernary

      Code style
      Medium

      Avoid if (x != y) ..; else ..;

      ConstantsInInterface

      Best practice
      Medium

      Avoid constants in interfaces. Interfaces define types

      ConstructorCallsOverridableMethod

      Error prone
      Critical

      Overridable method 'getAction' called during object construction

      DefaultLabelNotLastInSwitchStmt

      Best practice
      Medium

      The default label should be the last label in a switch statement

      DontCallThreadRun

      Unknown
      Minor

      Dont call Thread.run() explicitly

      DontUseFloatTypeForLoopIndices

      Error prone
      Medium

      Dont use floating point for loop indices. If you must use floating point

      DoubleCheckedLocking

      Unknown
      Critical

      Double checked locking is not thread safe in Java.

      EmptyMethodInAbstractClassShouldBeAbstract

      Code style
      Critical

      An empty method in an abstract class should be abstract instead

      EqualsNull

      Error prone
      Critical

      Avoid using equals() to compare against null

      ExtendsObject

      Code style
      Minor

      No need to explicitly extend Object.

      FieldDeclarationsShouldBeAtStartOfClass

      Code style
      Medium

      Fields should be declared at the top of the class

      FinalFieldCouldBeStatic

      Design
      Medium

      This final field could be made static

      ForLoopShouldBeWhileLoop

      Code style
      Medium

      This for loop could be simplified to a while loop

      IdempotentOperations

      Error prone
      Medium

      Avoid idempotent operations (like assigning a variable to itself).

      ImmutableField

      Design
      Medium

      Private field could be made final; it is only initialized in the declaration or constructor.

      InstantiationToGetClass

      Error prone
      Minor

      Avoid instantiating an object just to call getClass() on it; use the .class public member instead

      JumbledIncrementer

      Error prone
      Medium

      Avoid modifying an outer loop incrementer in an inner loop for update expression

      LogicInversion

      Design
      Medium

      Use opposite operator instead of the logic complement operator.

      MisplacedNullCheck

      Error prone
      Medium

      The null check here is misplaced; if the variable is null there will be a NullPointerException

      MissingBreakInSwitch

      Error prone
      Medium

      A switch statement does not contain a break

      MissingStaticMethodInNonInstantiatableClass

      Error prone
      Medium

      Class cannot be instantiated and does not provide any static methods or fields

      NonCaseLabelInSwitchStatement

      Error prone
      Medium

      A non-case label was present in a switch statement

      NonStaticInitializer

      Error prone
      Medium

      Non-static initializers are confusing

      NonThreadSafeSingleton

      Unknown
      Medium

      Singleton is not thread safe

      OptimizableToArrayCall

      Unknown
      Medium

      This call to Collection.toArray() may be optimizable

      OverrideBothEqualsAndHashcode

      Error prone
      Medium

      Ensure you override both equals() and hashCode()

      PositionLiteralsFirstInCaseInsensitiveComparisons

      Best practice
      Medium

      Position literals first in String comparisons for EqualsIgnoreCase

      PositionLiteralsFirstInComparisons

      Best practice
      Medium

      Position literals first in String comparisons

      PreserveStackTrace

      Best practice
      Medium

      New exception is thrown in catch block

      ReturnEmptyArrayRatherThanNull

      Error prone
      Critical

      Return an empty array rather than null.

      ReturnFromFinallyBlock

      Error prone
      Medium

      Avoid returning from a finally block

      SimpleDateFormatNeedsLocale

      Error prone
      Medium

      When instantiating a SimpleDateFormat object

      SimplifiedTernary

      Design
      Medium

      Ternary operators that can be simplified with || or &&

      SimplifyBooleanExpressions

      Design
      Medium

      Avoid unnecessary comparisons in boolean expressions

      SimplifyBooleanReturns

      Design
      Medium

      Avoid unnecessary if..then..else statements when returning booleans

      SimplifyConditional

      Design
      Medium

      No need to check for null before an instanceof

      SingleMethodSingleton

      Error prone
      High

      Class contains multiple getInstance methods. Please review.

      SingletonClassReturningNewInstance

      Error prone
      High

      getInstance method always creates a new object and hence does not comply to Singleton Design Pattern behaviour. Please review

      SwitchDensity

      Design
      Medium

      A high ratio of statements to labels in a switch statement. Consider refactoring.

      SwitchStmtsShouldHaveDefault

      Best practice
      Medium

      Switch statements should have a default label

      TooFewBranchesForASwitchStatement

      Unknown
      Medium

      A switch with less than three branches is inefficient

      UncommentedEmptyConstructor

      Documentation
      Medium

      Document empty constructor

      UncommentedEmptyMethodBody

      Documentation
      Medium

      Document empty method body

      UnconditionalIfStatement

      Error prone
      Medium

      Do not use if statements that are always true or always false

      UnnecessaryLocalBeforeReturn

      Code style
      Medium

      Consider simply returning the value vs storing it in local variable 'searchOptions'

      UnsynchronizedStaticDateFormatter

      Unknown
      Medium

      Static DateFormatter objects should be accessed in a synchronized manner

      UseCollectionIsEmpty

      Best practice
      Medium

      Substitute calls and make them more efficient

      UseLocaleWithCaseConversions

      Error prone
      Medium

      Use explicit locale when doing a String.toLowerCase()/toUpperCase() call

      UseNotifyAllInsteadOfNotify

      Unknown
      Medium

      Call Thread.notifyAll() rather than Thread.notify()

      UseVarargs

      Best practice
      Minor

      Consider using varargs for methods or constructors which take an array the last parameter.