This list is auto-generated from our sources. Each bug pattern includes code examples of both positive and negative cases; these examples are used in our regression test suite.
Patterns which are marked Experimental will not be evaluated against your code, unless you specifically configure Error Prone. The default checks are marked On by default, and each release promotes some experimental checks after we’ve vetted them against Google’s codebase.
AndroidInjection.inject() should always be invoked before calling super.lifecycleMethod()
Reference equality used to compare arrays
Arrays.fill(Object, Object) called with incompatible types.
hashcode method on array does not hash array contents
Calling toString on an array does not provide useful information
Arrays.asList does not autobox primitive arrays, as one might expect.
AsyncCallable should not return a null Future, only a Future whose result is null.
AsyncFunction should not return a null Future, only a Future whose result is null.
Arguments to AutoValue constructor are in the wrong order
Shift by an amount that is out of range
Object serialized in Bundle may have been flattened to base type.
The called constructor accepts a parameter with the same name and type as one of its caller's parameters, but its caller doesn't pass that parameter to it. It's likely that it was intended to.
Ignored return value of method that is annotated with @CheckReturnValue
Incompatible type as argument to Object-accepting Java collections method
Comparison to value that is out of range for the compared type
@CompatibleWith's value is not a type argument.
Non-compile-time constant expression passed to parameter with @CompileTimeConstant type annotation.
Non-trivial compile time constant boolean expressions shouldn't be used.
Compile-time constant expression overflows
Dagger @Provides methods may not return null unless annotated with @Nullable
Exception created but not thrown
Thread created but not started
This method should not be called.
== NaN always returns false; use the isNaN methods instead
== must be used in equals method to check equality to itself or an infinite loop will occur.
Switch case may fall through
The stream returned by Files.lines should be closed using try-with-resources
Method annotated @ForOverride must be protected or package-private and only invoked from declaring class, or from an override of the method
Invalid printf-style format string
Invalid format string passed to formatting method.
Casting a lambda to this @FunctionalInterface can cause a behavior change from casting to a functional superinterface, which is surprising to users. Prefer decorator methods to this surprising behavior.
Futures.getChecked requires a checked exception type with a standard constructor.
Calling getClass() on an annotation may return a proxy class
Calling getClass() on an object of type Class returns the Class object for java.lang.Class; you probably meant to operate on the object directly
Checks for unguarded accesses to fields and methods with @GuardedBy annotations
Scope annotation on implementation class of AssistedInject factory is not allowed
A constructor cannot have two @Assisted parameters of the same type unless they are disambiguated with named @Assisted annotations.
Although Guice allows injecting final fields, doing so is disallowed because the injected value may not be visible to other threads.
contains() is a legacy method that is equivalent to containsValue()
A binary expression where both operands are the same is usually incorrect.
Type declaration annotated with @Immutable is not immutable
Modifying an immutable collection is guaranteed to throw an exception and leave the collection unmodified
Passing argument to a generic method with an incompatible type.
The first argument to indexOf is a Unicode code point, and the second is the index to start the search from
This method always recurses, and will cause a StackOverflowError
A class can be annotated with at most one scope annotation.
Invalid syntax used for a regular expression
Invalid time zone identifier. TimeZone.getTimeZone(String) will silently return GMT instead of the time zone you intended.
The argument to Class#isInstance(Object) should not be a Class
Log tag too long, cannot exceed 23 characters.
Test method will not be run; please correct method signature (Should be public, non-static, and method name should begin with "test").
setUp() method will not be run; Please add a @Before annotation
tearDown() method will not be run; Please add an @After annotation
This looks like a test method but is not run; please add @Test or @Ignore, or, if this is a helper method, reduce its visibility.
An object is tested for reference equality to itself using JUnit library.
Abstract and default methods are not injectable with javax.inject.Inject
This pattern will silently corrupt certain byte sequences from the serialized protocol message. Use ByteString or byte directly
Loop condition is never modified in loop body.
Certain resources in
android.R.string have names that do not match their content
Switches on enum types should either handle all values, or have a default case.
Use of "YYYY" (week year) in a date pattern without "ww" (week in year). You probably meant to use "yyyy" (year) instead.
A bug in Mockito will cause this test to fail at runtime with a ClassCastException
Missing method call for verify(mock) here
Using a collection function with itself as the argument.
This class has more than one @Inject-annotated constructor. Please remove the @Inject annotation from all but one of them.
The result of this method must be closed.
The first argument to nCopies is the number of copies, and the second is the item to copy
Static import of type uses non-canonical name
@CompileTimeConstant parameters should be final or effectively final
Calling getAnnotation on an annotation that is not retained at runtime.
This conditional expression may evaluate to null, which will result in an NPE when the result is unboxed.
Comparison using reference equality instead of value equality
Annotations cannot be both Scope annotations and Qualifier annotations: this causes confusion when trying to use them.
This method is not annotated with @Inject, but it overrides a method that is annotated with @javax.inject.Inject. The method will not be Injected.
Declaring types inside package-info.java files is very bad form
Literal passed as first argument to Preconditions.checkNotNull() can never be null
First argument to
Preconditions.checkNotNull() is a primitive rather than an object reference
Using ::equals as an incompatible Predicate; the predicate will always return false
Protobuf fields cannot be null
To get the tag number of a protocol buffer enum, use getNumber() instead.
@Provides methods need to be declared in a Module to have any effect.
Use Random.nextInt(int). Random.nextInt() % n can have negative results
Return value of android.graphics.Rect.intersect() must be checked
Use of method or class annotated with @RestrictTo
Check for non-whitelisted callers to RestrictedApiChecker.
Return value of this method must be used
Variable assigned to itself
An object is compared to itself
Testing an object for equality with itself will always be true.
This method must be called with an even number of arguments.
Comparison of a size >= 0 is always true, did you intend to check for non-emptiness?
Calling toString on a Stream does not provide useful information
StringBuilder does not have a char constructor; this invokes the int constructor.
Suppressing "deprecated" is probably a typo for "deprecation"
throwIfUnchecked(knownCheckedException) is a no-op.
Throwing 'null' always results in a NullPointerException being thrown.
isEqualTo should not be used to test an object for equality with itself; the assertion will never fail.
Catching Throwable/Error masks failures from fail() or assert*() in the try block
Type parameter used as type qualifier
Non-generic methods should not be invoked with type arguments
Instance created but never used
Collection is modified in place, but the result is not used
Method reference is ambiguous
Arguments are in the wrong order or could be commented for clarity.
Arguments are swapped in assertEquals-like call
This assertion throws an AssertionError if it fails, which will be caught by an enclosing try block.
Classes that implement Annotation must override equals and hashCode. Consider using AutoAnnotation instead of implementing Annotation by hand.
Possible sign flip from narrowing conversion
valueOf or autoboxing provides better time and space performance
Mockito cannot mock final classes
Duration can be expressed more clearly with different units
Inner class is non-static but does not reference enclosing class
Class.newInstance() bypasses exception checking; prefer getDeclaredConstructor().newInstance()
The type of the array parameter of Collection.toArray needs to be compatible with the array type
Collector.of() should not use state
Class should not implement both
Implicit use of the platform default charset, which can result in e.g. non-ASCII characters being silently replaced with '?' in many environments
Double-checked locking on non-volatile fields is unsafe
Classes that override equals should also override hashCode.
An equality test between objects with incompatible types always returns false
If you return or throw from a finally, then values returned or thrown from the try-catch block will be ignored. Consider using try-with-resources instead.
Floating point literal loses precision
Classes extending PreferenceActivity must implement isValidFragment such that it does not unconditionally return true to prevent vulnerability to fragment injection attacks.
Subclasses of Fragment must be instantiable via Class#newInstance(): the class must be public, static and have a public nullary constructor
Overloads will be ambiguous when passing lambda arguments
Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future.
Calling getClass() on an enum may return a subclass of the enum type
Annotations should always be immutable
Enums should always be immutable
This annotation has incompatible modifiers as specified by its @IncompatibleModifiers annotation
This for loop increments the same variable in the header and in the body
Constructors on abstract classes are never directly @Injected, only the constructors of their subclasses can be @Inject'ed.
Please also override int read(byte, int, int), otherwise multi-byte reads from this input stream are likely to be slow.
Casting inside an if block should be plausibly consistent with the instanceof type
Expression of type int may overflow before being assigned to a long
Class should not implement both
Floating-point comparison without error tolerance
Some JUnit4 construct cannot be used in a JUnit3 context. Convert your class to JUnit4 style to use them.
Test class inherits from JUnit 3's TestCase but has JUnit 4 @Test annotations.
Never reuse class names from java.lang
Suggests alternatives to obsolete JDK classes.
Assignment where a boolean expression was expected; use == if this assignment wasn't expected or add parentheses for clarity.
Not calling fail() when expecting an exception masks bugs
method overrides method in supertype; expected @Override
Multiple calls to either parallel or sequential are unnecessary and cause confusion.
Constant field declarations should use the immutable type (such as ImmutableList) instead of the general collection interface type (such as List)
Parameter name in argument comment is incorrect
Compound assignments may hide dangerous casts
Nested instanceOf conditions of disjoint types create blocks of code that never execute
This update of a volatile variable is non-atomic
equals method doesn't override Object.equals
Constructors should not be annotated with @Nullable since they cannot return null
@Nullable should not be used for primitive types since they cannot be null
void-returning methods should not be annotated with @Nullable, since they cannot return null
Use grouping parenthesis to make the operator precedence explicit
One should not call optional.get() inside an if statement that checks !optional.isPresent
To return a custom message with a Throwable class, one should override getMessage() instead of toString() for Throwable.
Varargs doesn't agree for overridden method
This method is not annotated with @Inject, but it overrides a method that is annotated with @com.google.inject.Inject. Guice will inject this method, and it is recommended to annotate it explicitly.
Overshadowing variables of superclass causes confusion and errors
/* name= */-style comments on actual parameters where the name doesn't match the formal parameter
Preconditions only accepts the %s placeholder in error message strings
Protobuf fields cannot be null, so this check is redundant
Comparison using reference equality instead of value equality
This annotation is missing required modifiers as specified by its @RequiredModifiers annotation
Prefer the short-circuiting boolean operators && and || to & and |.
SimpleDateFormat is not thread-safe, and should not be used as a constant field.
Writes to static fields should not be guarded by instance locks
Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects.
Thread.join needs to be surrounded by a loop until it succeeds, as in Uninterruptibles.joinUninterruptibly.
Truth Library assert is called on a constant.
Type parameter declaration overrides another type parameter already declared
Declaring a type parameter that is only used in the return type is a misuse of generics: operations on the type parameter are unchecked, it hides unsafe casts at invocations of the method, and it interacts badly with method overload resolution.
Creation of a Set/HashSet/HashMap of java.net.URL. equals() and hashCode() of java.net.URL class make blocking internet connections.
Unsynchronized method overrides a synchronized method.
Java assert is used in test. For testing purposes Assert.* matchers should be used.
Because of spurious wakeups, Object.wait() and Condition.await() must always be called in a loop
A wakelock acquired with a timeout may be released by the system before calling
release, even after checking
isHeld(). If so, it will throw a RuntimeException. Please wrap in a try/catch block.
@AssistedInject and @Inject cannot be used on the same constructor.
@AutoFactory and @Inject should not be used in the same type.
The source file name should match the name of the top-level class it contains
This comparison method violates the contract
Deprecated item is not annotated with @Deprecated
Division by integer literal zero
Empty statement after if
DoubleMath.fuzzyEquals should never be used in an Object.equals() method
A scoping annotation's Target should include TYPE and METHOD.
Using more than one qualifier annotation on the same element is not allowed.
Scope annotation on an interface or abstact class is not allowed
Scoping and qualifier annotations must have runtime retention.
Injected constructors cannot be optional nor have binding annotations
A standard cryptographic operation is used in a mode that is prone to vulnerabilities
Path implements Iterable<Path>; prefer Collection<Path> for clarity
jMock tests must have a @RunWith(JMock.class) annotation, or the Mockery field must have a @Rule JUnit annotation
@javax.inject.Inject cannot be put on a final field.
This method does not acquire the locks specified by its @LockMethod annotation
Prefer 'L' to 'l' for the suffix to long literals
@NoAllocation was specified on this method, but something was found that would trigger an allocation
Numeric comparison using reference equality instead of value equality
Method parameter has wrong package
Comparing protobuf fields of type String using reference equality
Qualifiers/Scope annotations on @Inject methods don't have any effect. Move the qualifier annotation to the binding location.
Static and default interface methods are not natively supported on older Android devices.
This method does not acquire the locks specified by its @UnlockMethod annotation
Assertions may be disabled at runtime and do not guarantee that execution will halt here; consider throwing an exception instead
@AssistedInject and @Inject should not be used on different constructors in the same class.
BigDecimal(double) and BigDecimal.valueOf(double) may lose precision, prefer BigDecimal(String) or BigDecimal(long)
This code declares a binding for a common value type without a Qualifier annotation.
Constructors should not invoke overridable methods.
Constructors should not pass the 'this' reference out in method invocations, since the object may not be fully constructed.
Empty top-level type declaration
Calls to ExpectedException#expect should always be followed by exactly one statement.
Hardcoded reference to /sdcard
The ordering of parameters in overloaded methods should be as consistent as possible (when viewed from left to right)
The Google Java Style Guide requires that each switch statement includes a default statement group, even if it contains no code. (This requirement is lifted for any switch statement that covers all values of an enum.)
Method return type should use the immutable type (such as ImmutableList) instead of the general collection interface type (such as List)
Static import of member uses non-canonical name
Passing a primitive array to a varargs method is usually wrong
BugChecker has incorrect ProvidesFix tag, please update
Injection frameworks currently don't understand Qualifiers in TYPE_PARAMETER or TYPE_USE contexts.
Thrown exception is a subtype of another
A static variable or method should be qualified with a class name, not expression
String comparison using reference equality instead of value equality
Using @Test(expected=…) is discouraged, since the test will pass if any statement in the test method throws the expected exception
Switch handles all enum values; an explicit default case is unnecessary and defeats error checking for non-exhaustive switches.
Non-constant variable missing @Var annotation
Field name is CONSTANT_CASE, but field is not static and final
@Multibinds is a more efficient and declarative mechanism for ensuring that a set multibinding is present in the graph.
Fields that can be null should be annotated @Nullable
A private method that does not reference the enclosing instance can be static
C-style array declarations should not be used
Variable declarations should declare only one variable
Source files should not contain multiple top-level class declarations
Avoid having multiple unary operators acting on the same variable in a method call
Package names should match the directory they are declared in
Non-standard parameter comment; prefer
Method parameters that aren't checked for null shouldn't be annotated @Nullable
Add a private constructor to modules that will not be instantiated by Dagger.
Utility classes (only static members) are not designed to be instantiated and should be made noninstantiable with a default constructor.
Methods that can return null should be annotated @Nullable
Unchecked exceptions do not need to be declared in the method signature.
Constructors and methods with the same name should appear sequentially with no other code in between
Unnecessary call to NullPointerTester#setDefault
Using static imports for types is unnecessary
@Binds is a more efficient and declarative mechanism for delegating a binding.
Wildcard imports, static or otherwise, should not be used