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
Warning

This abstract class does not have any abstract methods

Learn more

AssignmentToNonFinalStatic

Error prone
Warning

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

AvoidDecimalLiteralsInBigDecimalConstructor

Error prone
Warning

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

AvoidDeeplyNestedIfStmts

Design
Warning

Deeply nested if..then statements are hard to read

AvoidInstanceofChecksInCatchClause

Error prone
Warning

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

AvoidProtectedFieldInFinalClass

Code style
Warning

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

AvoidProtectedMethodInFinalClassNotExtending

Code style
Warning

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

AvoidSynchronizedAtMethodLevel

Unknown
Warning

Use block level rather than method level synchronization

AvoidThreadGroup

Unknown
Warning

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

AvoidUsingHardCodedIP

Best practice
Warning

Do not hard code the IP address

AvoidUsingOctalValues

Error prone
Warning

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

BadComparison

Error prone
Warning

Avoid equality comparisons with Double.NaN

BigIntegerInstantiation

Unknown
Warning

Dont create instances of already existing BigInteger and BigDecimal.

CheckResultSet

Best practice
Warning

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

CheckSkipResult

Error prone
Warning

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
Warning

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

CloseResource

Error prone
Warning

Ensure that resources like this PipedWriter object are closed after use

CollapsibleIfStatements

Design
Warning

These nested if statements could be combined

CompareObjectsWithEquals

Error prone
Warning

Use equals() to compare object references.

ConfusingTernary

Code style
Warning

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

ConstantsInInterface

Best practice
Warning

Avoid constants in interfaces. Interfaces define types

DefaultLabelNotLastInSwitchStmt

Best practice
Warning

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

DontUseFloatTypeForLoopIndices

Error prone
Warning

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

FieldDeclarationsShouldBeAtStartOfClass

Code style
Warning

Fields should be declared at the top of the class

FinalFieldCouldBeStatic

Design
Warning

This final field could be made static

ForLoopShouldBeWhileLoop

Code style
Warning

This for loop could be simplified to a while loop

IdempotentOperations

Error prone
Warning

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

ImmutableField

Design
Warning

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

JumbledIncrementer

Error prone
Warning

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

LogicInversion

Design
Warning

Use opposite operator instead of the logic complement operator.

MisplacedNullCheck

Error prone
Warning

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

MissingBreakInSwitch

Error prone
Warning

A switch statement does not contain a break

MissingStaticMethodInNonInstantiatableClass

Error prone
Warning

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

NonCaseLabelInSwitchStatement

Error prone
Warning

A non-case label was present in a switch statement

NonStaticInitializer

Error prone
Warning

Non-static initializers are confusing

NonThreadSafeSingleton

Unknown
Warning

Singleton is not thread safe

OptimizableToArrayCall

Unknown
Warning

This call to Collection.toArray() may be optimizable

OverrideBothEqualsAndHashcode

Error prone
Warning

Ensure you override both equals() and hashCode()

PositionLiteralsFirstInCaseInsensitiveComparisons

Best practice
Warning

Position literals first in String comparisons for EqualsIgnoreCase

PositionLiteralsFirstInComparisons

Best practice
Warning

Position literals first in String comparisons

PreserveStackTrace

Best practice
Warning

New exception is thrown in catch block

ReturnFromFinallyBlock

Error prone
Warning

Avoid returning from a finally block

SimpleDateFormatNeedsLocale

Error prone
Warning

When instantiating a SimpleDateFormat object

SimplifiedTernary

Design
Warning

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

SimplifyBooleanExpressions

Design
Warning

Avoid unnecessary comparisons in boolean expressions

SimplifyBooleanReturns

Design
Warning

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

SimplifyConditional

Design
Warning

No need to check for null before an instanceof

SwitchDensity

Design
Warning

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

SwitchStmtsShouldHaveDefault

Best practice
Warning

Switch statements should have a default label

TooFewBranchesForASwitchStatement

Unknown
Warning

A switch with less than three branches is inefficient

UncommentedEmptyConstructor

Documentation
Warning

Document empty constructor

UncommentedEmptyMethodBody

Documentation
Warning

Document empty method body

UnconditionalIfStatement

Error prone
Warning

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

UnnecessaryLocalBeforeReturn

Code style
Warning

Consider simply returning the value vs storing it in local variable

UnsynchronizedStaticDateFormatter

Unknown
Warning

Static DateFormatter objects should be accessed in a synchronized manner

UseCollectionIsEmpty

Best practice
Warning

Substitute calls and make them more efficient. (e.g. is .useEmpty() instead of .size() == 0)

UseLocaleWithCaseConversions

Error prone
Warning

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

UseNotifyAllInsteadOfNotify

Unknown
Warning

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

We use cookies to improve your site experience, including analytics cookies to understand how you use our product and design better experiences. Please read our Cookie Policy.