blob: 77b80a471dcd4b561c539945578ea0c55712b63e [file] [log] [blame]
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -08001#
2# Copyright (C) 2019 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Warning patterns for Java compiler tools."""
17
18from severity import Severity
19
20
21def java_warn(severity, description, pattern_list):
22 return {
23 'category': 'Java',
24 'severity': severity,
25 'description': 'Java: ' + description,
26 'patterns': pattern_list
27 }
28
29
30def java_high(description, pattern_list):
31 return java_warn(Severity.HIGH, description, pattern_list)
32
33
34def java_medium(description, pattern_list):
35 return java_warn(Severity.MEDIUM, description, pattern_list)
36
37
38def java_low(description, pattern_list):
39 return java_warn(Severity.LOW, description, pattern_list)
40
41
42patterns = [
43 # pylint:disable=line-too-long,g-inconsistent-quotes
44 # Warnings from Javac
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -080045 java_medium('Use of deprecated',
46 [r'.*: warning: \[deprecation\] .+',
47 r'.*: warning: \[removal\] .+ has been deprecated and marked for removal$']),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -080048 java_medium('Unchecked conversion',
49 [r'.*: warning: \[unchecked\] .+']),
50 # Warnings generated by Error Prone
51 java_medium('Non-ascii characters used, but ascii encoding specified',
52 [r".*: warning: unmappable character for encoding ascii"]),
53 java_medium('Non-varargs call of varargs method with inexact argument type for last parameter',
54 [r".*: warning: non-varargs call of varargs method with inexact argument type for last parameter"]),
55 java_medium('Unchecked method invocation',
56 [r".*: warning: \[unchecked\] unchecked method invocation: .+ in class .+"]),
57 java_medium('Unchecked conversion',
58 [r".*: warning: \[unchecked\] unchecked conversion"]),
59 java_medium('_ used as an identifier',
60 [r".*: warning: '_' used as an identifier"]),
61 java_medium('hidden superclass',
62 [r".*: warning: .* stripped of .* superclass .* \[HiddenSuperclass\]"]),
63 java_high('Use of internal proprietary API',
64 [r".*: warning: .* is internal proprietary API and may be removed"]),
65 java_low('Use parameter comments to document ambiguous literals',
66 [r".*: warning: \[BooleanParameter\] .+"]),
67 java_low('This class\'s name looks like a Type Parameter.',
68 [r".*: warning: \[ClassNamedLikeTypeParameter\] .+"]),
69 java_low('Field name is CONSTANT_CASE, but field is not static and final',
70 [r".*: warning: \[ConstantField\] .+"]),
71 java_low('@Multibinds is a more efficient and declarative mechanism for ensuring that a set multibinding is present in the graph.',
72 [r".*: warning: \[EmptySetMultibindingContributions\] .+"]),
73 java_low('Prefer assertThrows to ExpectedException',
74 [r".*: warning: \[ExpectedExceptionRefactoring\] .+"]),
75 java_low('This field is only assigned during initialization; consider making it final',
76 [r".*: warning: \[FieldCanBeFinal\] .+"]),
77 java_low('Fields that can be null should be annotated @Nullable',
78 [r".*: warning: \[FieldMissingNullable\] .+"]),
79 java_low('Refactors uses of the JSR 305 @Immutable to Error Prone\'s annotation',
80 [r".*: warning: \[ImmutableRefactoring\] .+"]),
81 java_low(u'Use Java\'s utility functional interfaces instead of Function\u003cA, B> for primitive types.',
82 [r".*: warning: \[LambdaFunctionalInterface\] .+"]),
83 java_low('A private method that does not reference the enclosing instance can be static',
84 [r".*: warning: \[MethodCanBeStatic\] .+"]),
85 java_low('C-style array declarations should not be used',
86 [r".*: warning: \[MixedArrayDimensions\] .+"]),
87 java_low('Variable declarations should declare only one variable',
88 [r".*: warning: \[MultiVariableDeclaration\] .+"]),
89 java_low('Source files should not contain multiple top-level class declarations',
90 [r".*: warning: \[MultipleTopLevelClasses\] .+"]),
91 java_low('Avoid having multiple unary operators acting on the same variable in a method call',
92 [r".*: warning: \[MultipleUnaryOperatorsInMethodCall\] .+"]),
93 java_low('Package names should match the directory they are declared in',
94 [r".*: warning: \[PackageLocation\] .+"]),
95 java_low('Non-standard parameter comment; prefer `/* paramName= */ arg`',
96 [r".*: warning: \[ParameterComment\] .+"]),
97 java_low('Method parameters that aren\'t checked for null shouldn\'t be annotated @Nullable',
98 [r".*: warning: \[ParameterNotNullable\] .+"]),
99 java_low('Add a private constructor to modules that will not be instantiated by Dagger.',
100 [r".*: warning: \[PrivateConstructorForNoninstantiableModule\] .+"]),
101 java_low('Utility classes (only static members) are not designed to be instantiated and should be made noninstantiable with a default constructor.',
102 [r".*: warning: \[PrivateConstructorForUtilityClass\] .+"]),
103 java_low('Unused imports',
104 [r".*: warning: \[RemoveUnusedImports\] .+"]),
105 java_low('Methods that can return null should be annotated @Nullable',
106 [r".*: warning: \[ReturnMissingNullable\] .+"]),
107 java_low('Scopes on modules have no function and will soon be an error.',
108 [r".*: warning: \[ScopeOnModule\] .+"]),
109 java_low('The default case of a switch should appear at the end of the last statement group',
110 [r".*: warning: \[SwitchDefault\] .+"]),
111 java_low('Prefer assertThrows to @Test(expected=...)',
112 [r".*: warning: \[TestExceptionRefactoring\] .+"]),
113 java_low('Unchecked exceptions do not need to be declared in the method signature.',
114 [r".*: warning: \[ThrowsUncheckedException\] .+"]),
115 java_low('Prefer assertThrows to try/fail',
116 [r".*: warning: \[TryFailRefactoring\] .+"]),
117 java_low('Type parameters must be a single letter with an optional numeric suffix, or an UpperCamelCase name followed by the letter \'T\'.',
118 [r".*: warning: \[TypeParameterNaming\] .+"]),
119 java_low('Constructors and methods with the same name should appear sequentially with no other code in between. Please re-order or re-name methods.',
120 [r".*: warning: \[UngroupedOverloads\] .+"]),
121 java_low('Unnecessary call to NullPointerTester#setDefault',
122 [r".*: warning: \[UnnecessarySetDefault\] .+"]),
123 java_low('Using static imports for types is unnecessary',
124 [r".*: warning: \[UnnecessaryStaticImport\] .+"]),
125 java_low('@Binds is a more efficient and declarative mechanism for delegating a binding.',
126 [r".*: warning: \[UseBinds\] .+"]),
127 java_low('Wildcard imports, static or otherwise, should not be used',
128 [r".*: warning: \[WildcardImport\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800129 java_medium('AcronymName',
130 [r".*\.java:.*: warning: .+ \[AcronymName\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800131 java_medium('Method reference is ambiguous',
132 [r".*: warning: \[AmbiguousMethodReference\] .+"]),
133 java_medium('This method passes a pair of parameters through to String.format, but the enclosing method wasn\'t annotated @FormatMethod. Doing so gives compile-time rather than run-time protection against malformed format strings.',
134 [r".*: warning: \[AnnotateFormatMethod\] .+"]),
135 java_medium('Annotations should be positioned after Javadocs, but before modifiers..',
136 [r".*: warning: \[AnnotationPosition\] .+"]),
137 java_medium('Arguments are in the wrong order or could be commented for clarity.',
138 [r".*: warning: \[ArgumentSelectionDefectChecker\] .+"]),
139 java_medium('Arrays do not override equals() or hashCode, so comparisons will be done on reference equality only. If neither deduplication nor lookup are needed, consider using a List instead. Otherwise, use IdentityHashMap/Set, a Map from a library that handles object arrays, or an Iterable/List of pairs.',
140 [r".*: warning: \[ArrayAsKeyOfSetOrMap\] .+"]),
141 java_medium('Arguments are swapped in assertEquals-like call',
142 [r".*: warning: \[AssertEqualsArgumentOrderChecker\] .+"]),
143 java_medium('Assertions may be disabled at runtime and do not guarantee that execution will halt here; consider throwing an exception instead',
144 [r".*: warning: \[AssertFalse\] .+"]),
145 java_medium('The lambda passed to assertThrows should contain exactly one statement',
146 [r".*: warning: \[AssertThrowsMultipleStatements\] .+"]),
147 java_medium('This assertion throws an AssertionError if it fails, which will be caught by an enclosing try block.',
148 [r".*: warning: \[AssertionFailureIgnored\] .+"]),
149 java_medium('@AssistedInject and @Inject should not be used on different constructors in the same class.',
150 [r".*: warning: \[AssistedInjectAndInjectOnConstructors\] .+"]),
151 java_medium('Make toString(), hashCode() and equals() final in AutoValue classes, so it is clear to readers that AutoValue is not overriding them',
152 [r".*: warning: \[AutoValueFinalMethods\] .+"]),
153 java_medium('Classes that implement Annotation must override equals and hashCode. Consider using AutoAnnotation instead of implementing Annotation by hand.',
154 [r".*: warning: \[BadAnnotationImplementation\] .+"]),
155 java_medium('Possible sign flip from narrowing conversion',
156 [r".*: warning: \[BadComparable\] .+"]),
157 java_medium('Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context exactly which type is being referred to. Qualifying the name with that of the containing class can make the code clearer.',
158 [r".*: warning: \[BadImport\] .+"]),
159 java_medium('instanceof used in a way that is equivalent to a null check.',
160 [r".*: warning: \[BadInstanceof\] .+"]),
161 java_medium('BigDecimal#equals has surprising behavior: it also compares scale.',
162 [r".*: warning: \[BigDecimalEquals\] .+"]),
163 java_medium('new BigDecimal(double) loses precision in this case.',
164 [r".*: warning: \[BigDecimalLiteralDouble\] .+"]),
165 java_medium('A call to Binder.clearCallingIdentity() should be followed by Binder.restoreCallingIdentity() in a finally block. Otherwise the wrong Binder identity may be used by subsequent code.',
166 [r".*: warning: \[BinderIdentityRestoredDangerously\] .+"]),
167 java_medium('This code declares a binding for a common value type without a Qualifier annotation.',
168 [r".*: warning: \[BindingToUnqualifiedCommonType\] .+"]),
169 java_medium('valueOf or autoboxing provides better time and space performance',
170 [r".*: warning: \[BoxedPrimitiveConstructor\] .+"]),
171 java_medium('ByteBuffer.array() shouldn\'t be called unless ByteBuffer.arrayOffset() is used or if the ByteBuffer was initialized using ByteBuffer.wrap() or ByteBuffer.allocate().',
172 [r".*: warning: \[ByteBufferBackingArray\] .+"]),
173 java_medium('Mockito cannot mock final classes',
174 [r".*: warning: \[CannotMockFinalClass\] .+"]),
175 java_medium('Duration can be expressed more clearly with different units',
176 [r".*: warning: \[CanonicalDuration\] .+"]),
177 java_medium('Logging or rethrowing exceptions should usually be preferred to catching and calling printStackTrace',
178 [r".*: warning: \[CatchAndPrintStackTrace\] .+"]),
179 java_medium('Ignoring exceptions and calling fail() is unnecessary, and makes test output less useful',
180 [r".*: warning: \[CatchFail\] .+"]),
181 java_medium('Inner class is non-static but does not reference enclosing class',
182 [r".*: warning: \[ClassCanBeStatic\] .+"]),
183 java_medium('Class.newInstance() bypasses exception checking; prefer getDeclaredConstructor().newInstance()',
184 [r".*: warning: \[ClassNewInstance\] .+"]),
185 java_medium('Providing Closeable resources makes their lifecycle unclear',
186 [r".*: warning: \[CloseableProvides\] .+"]),
187 java_medium('The type of the array parameter of Collection.toArray needs to be compatible with the array type',
188 [r".*: warning: \[CollectionToArraySafeParameter\] .+"]),
189 java_medium('Collector.of() should not use state',
190 [r".*: warning: \[CollectorShouldNotUseState\] .+"]),
191 java_medium('Class should not implement both `Comparable` and `Comparator`',
192 [r".*: warning: \[ComparableAndComparator\] .+"]),
193 java_medium('Constructors should not invoke overridable methods.',
194 [r".*: warning: \[ConstructorInvokesOverridable\] .+"]),
195 java_medium('Constructors should not pass the \'this\' reference out in method invocations, since the object may not be fully constructed.',
196 [r".*: warning: \[ConstructorLeaksThis\] .+"]),
197 java_medium('DateFormat is not thread-safe, and should not be used as a constant field.',
198 [r".*: warning: \[DateFormatConstant\] .+"]),
199 java_medium('Implicit use of the platform default charset, which can result in differing behaviour between JVM executions or incorrect behavior if the encoding of the data source doesn\'t match expectations.',
200 [r".*: warning: \[DefaultCharset\] .+"]),
201 java_medium('Avoid deprecated Thread methods; read the method\'s javadoc for details.',
202 [r".*: warning: \[DeprecatedThreadMethods\] .+"]),
203 java_medium('Prefer collection factory methods or builders to the double-brace initialization pattern.',
204 [r".*: warning: \[DoubleBraceInitialization\] .+"]),
205 java_medium('Double-checked locking on non-volatile fields is unsafe',
206 [r".*: warning: \[DoubleCheckedLocking\] .+"]),
207 java_medium('Empty top-level type declaration',
208 [r".*: warning: \[EmptyTopLevelDeclaration\] .+"]),
209 java_medium('equals() implementation may throw NullPointerException when given null',
210 [r".*: warning: \[EqualsBrokenForNull\] .+"]),
211 java_medium('Overriding Object#equals in a non-final class by using getClass rather than instanceof breaks substitutability of subclasses.',
212 [r".*: warning: \[EqualsGetClass\] .+"]),
213 java_medium('Classes that override equals should also override hashCode.',
214 [r".*: warning: \[EqualsHashCode\] .+"]),
215 java_medium('An equality test between objects with incompatible types always returns false',
216 [r".*: warning: \[EqualsIncompatibleType\] .+"]),
217 java_medium('The contract of #equals states that it should return false for incompatible types, while this implementation may throw ClassCastException.',
218 [r".*: warning: \[EqualsUnsafeCast\] .+"]),
219 java_medium('Implementing #equals by just comparing hashCodes is fragile. Hashes collide frequently, and this will lead to false positives in #equals.',
220 [r".*: warning: \[EqualsUsingHashCode\] .+"]),
221 java_medium('Calls to ExpectedException#expect should always be followed by exactly one statement.',
222 [r".*: warning: \[ExpectedExceptionChecker\] .+"]),
223 java_medium('When only using JUnit Assert\'s static methods, you should import statically instead of extending.',
224 [r".*: warning: \[ExtendingJUnitAssert\] .+"]),
225 java_medium('Switch case may fall through',
226 [r".*: warning: \[FallThrough\] .+"]),
227 java_medium('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.',
228 [r".*: warning: \[Finally\] .+"]),
229 java_medium('Use parentheses to make the precedence explicit',
230 [r".*: warning: \[FloatCast\] .+"]),
231 java_medium('This fuzzy equality check is using a tolerance less than the gap to the next number. You may want a less restrictive tolerance, or to assert equality.',
232 [r".*: warning: \[FloatingPointAssertionWithinEpsilon\] .+"]),
233 java_medium('Floating point literal loses precision',
234 [r".*: warning: \[FloatingPointLiteralPrecision\] .+"]),
235 java_medium('Classes extending PreferenceActivity must implement isValidFragment such that it does not unconditionally return true to prevent vulnerability to fragment injection attacks.',
236 [r".*: warning: \[FragmentInjection\] .+"]),
237 java_medium('Subclasses of Fragment must be instantiable via Class#newInstance(): the class must be public, static and have a public nullary constructor',
238 [r".*: warning: \[FragmentNotInstantiable\] .+"]),
239 java_medium('Overloads will be ambiguous when passing lambda arguments',
240 [r".*: warning: \[FunctionalInterfaceClash\] .+"]),
241 java_medium('Return value of methods returning Future must be checked. Ignoring returned Futures suppresses exceptions thrown from the code that completes the Future.',
242 [r".*: warning: \[FutureReturnValueIgnored\] .+"]),
243 java_medium('Calling getClass() on an enum may return a subclass of the enum type',
244 [r".*: warning: \[GetClassOnEnum\] .+"]),
245 java_medium('Hardcoded reference to /sdcard',
246 [r".*: warning: \[HardCodedSdCardPath\] .+"]),
247 java_medium('Hiding fields of superclasses may cause confusion and errors',
248 [r".*: warning: \[HidingField\] .+"]),
249 java_medium('Annotations should always be immutable',
250 [r".*: warning: \[ImmutableAnnotationChecker\] .+"]),
251 java_medium('Enums should always be immutable',
252 [r".*: warning: \[ImmutableEnumChecker\] .+"]),
253 java_medium('This annotation has incompatible modifiers as specified by its @IncompatibleModifiers annotation',
254 [r".*: warning: \[IncompatibleModifiers\] .+"]),
255 java_medium('It is confusing to have a field and a parameter under the same scope that differ only in capitalization.',
256 [r".*: warning: \[InconsistentCapitalization\] .+"]),
257 java_medium('Including fields in hashCode which are not compared in equals violates the contract of hashCode.',
258 [r".*: warning: \[InconsistentHashCode\] .+"]),
259 java_medium('The ordering of parameters in overloaded methods should be as consistent as possible (when viewed from left to right)',
260 [r".*: warning: \[InconsistentOverloads\] .+"]),
261 java_medium('This for loop increments the same variable in the header and in the body',
262 [r".*: warning: \[IncrementInForLoopAndHeader\] .+"]),
263 java_medium('Constructors on abstract classes are never directly @Injected, only the constructors of their subclasses can be @Inject\'ed.',
264 [r".*: warning: \[InjectOnConstructorOfAbstractClass\] .+"]),
265 java_medium('Please also override int read(byte[], int, int), otherwise multi-byte reads from this input stream are likely to be slow.',
266 [r".*: warning: \[InputStreamSlowMultibyteRead\] .+"]),
267 java_medium('Casting inside an if block should be plausibly consistent with the instanceof type',
268 [r".*: warning: \[InstanceOfAndCastMatchWrongType\] .+"]),
269 java_medium('Expression of type int may overflow before being assigned to a long',
270 [r".*: warning: \[IntLongMath\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800271 java_medium('IntentBuilderName',
272 [r".*\.java:.*: warning: .+ \[IntentBuilderName\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800273 java_medium('This @param tag doesn\'t refer to a parameter of the method.',
274 [r".*: warning: \[InvalidParam\] .+"]),
275 java_medium('This tag is invalid.',
276 [r".*: warning: \[InvalidTag\] .+"]),
277 java_medium('The documented method doesn\'t actually throw this checked exception.',
278 [r".*: warning: \[InvalidThrows\] .+"]),
279 java_medium('Class should not implement both `Iterable` and `Iterator`',
280 [r".*: warning: \[IterableAndIterator\] .+"]),
281 java_medium('Floating-point comparison without error tolerance',
282 [r".*: warning: \[JUnit3FloatingPointComparisonWithoutDelta\] .+"]),
283 java_medium('Some JUnit4 construct cannot be used in a JUnit3 context. Convert your class to JUnit4 style to use them.',
284 [r".*: warning: \[JUnit4ClassUsedInJUnit3\] .+"]),
285 java_medium('Test class inherits from JUnit 3\'s TestCase but has JUnit 4 @Test annotations.',
286 [r".*: warning: \[JUnitAmbiguousTestClass\] .+"]),
287 java_medium('Never reuse class names from java.lang',
288 [r".*: warning: \[JavaLangClash\] .+"]),
289 java_medium('Suggests alternatives to obsolete JDK classes.',
290 [r".*: warning: \[JdkObsolete\] .+"]),
291 java_medium('Calls to Lock#lock should be immediately followed by a try block which releases the lock.',
292 [r".*: warning: \[LockNotBeforeTry\] .+"]),
293 java_medium('Assignment where a boolean expression was expected; use == if this assignment wasn\'t expected or add parentheses for clarity.',
294 [r".*: warning: \[LogicalAssignment\] .+"]),
295 java_medium('Math.abs does not always give a positive result. Please consider other methods for positive random numbers.',
296 [r".*: warning: \[MathAbsoluteRandom\] .+"]),
297 java_medium('Switches on enum types should either handle all values, or have a default case.',
298 [r".*: warning: \[MissingCasesInEnumSwitch\] .+"]),
299 java_medium('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.)',
300 [r".*: warning: \[MissingDefault\] .+"]),
301 java_medium('Not calling fail() when expecting an exception masks bugs',
302 [r".*: warning: \[MissingFail\] .+"]),
303 java_medium('method overrides method in supertype; expected @Override',
304 [r".*: warning: \[MissingOverride\] .+"]),
305 java_medium('A collection or proto builder was created, but its values were never accessed.',
306 [r".*: warning: \[ModifiedButNotUsed\] .+"]),
307 java_medium('Modifying a collection while iterating over it in a loop may cause a ConcurrentModificationException to be thrown.',
308 [r".*: warning: \[ModifyCollectionInEnhancedForLoop\] .+"]),
309 java_medium('Multiple calls to either parallel or sequential are unnecessary and cause confusion.',
310 [r".*: warning: \[MultipleParallelOrSequentialCalls\] .+"]),
311 java_medium('Constant field declarations should use the immutable type (such as ImmutableList) instead of the general collection interface type (such as List)',
312 [r".*: warning: \[MutableConstantField\] .+"]),
313 java_medium('Method return type should use the immutable type (such as ImmutableList) instead of the general collection interface type (such as List)',
314 [r".*: warning: \[MutableMethodReturnType\] .+"]),
315 java_medium('Compound assignments may hide dangerous casts',
316 [r".*: warning: \[NarrowingCompoundAssignment\] .+"]),
317 java_medium('Nested instanceOf conditions of disjoint types create blocks of code that never execute',
318 [r".*: warning: \[NestedInstanceOfConditions\] .+"]),
319 java_medium('Instead of returning a functional type, return the actual type that the returned function would return and use lambdas at use site.',
320 [r".*: warning: \[NoFunctionalReturnType\] .+"]),
321 java_medium('This update of a volatile variable is non-atomic',
322 [r".*: warning: \[NonAtomicVolatileUpdate\] .+"]),
323 java_medium('Static import of member uses non-canonical name',
324 [r".*: warning: \[NonCanonicalStaticMemberImport\] .+"]),
325 java_medium('equals method doesn\'t override Object.equals',
326 [r".*: warning: \[NonOverridingEquals\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800327 java_medium('Not closeable',
328 [r".*\.java:.*: warning: .+ \[NotCloseable\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800329 java_medium('Constructors should not be annotated with @Nullable since they cannot return null',
330 [r".*: warning: \[NullableConstructor\] .+"]),
331 java_medium('Dereference of possibly-null value',
332 [r".*: warning: \[NullableDereference\] .+"]),
333 java_medium('@Nullable should not be used for primitive types since they cannot be null',
334 [r".*: warning: \[NullablePrimitive\] .+"]),
335 java_medium('void-returning methods should not be annotated with @Nullable, since they cannot return null',
336 [r".*: warning: \[NullableVoid\] .+"]),
337 java_medium('Calling toString on Objects that don\'t override toString() doesn\'t provide useful information',
338 [r".*: warning: \[ObjectToString\] .+"]),
339 java_medium('Objects.hashCode(Object o) should not be passed a primitive value',
340 [r".*: warning: \[ObjectsHashCodePrimitive\] .+"]),
341 java_medium('Use grouping parenthesis to make the operator precedence explicit',
342 [r".*: warning: \[OperatorPrecedence\] .+"]),
343 java_medium('One should not call optional.get() inside an if statement that checks !optional.isPresent',
344 [r".*: warning: \[OptionalNotPresent\] .+"]),
345 java_medium('String literal contains format specifiers, but is not passed to a format method',
346 [r".*: warning: \[OrphanedFormatString\] .+"]),
347 java_medium('To return a custom message with a Throwable class, one should override getMessage() instead of toString() for Throwable.',
348 [r".*: warning: \[OverrideThrowableToString\] .+"]),
349 java_medium('Varargs doesn\'t agree for overridden method',
350 [r".*: warning: \[Overrides\] .+"]),
351 java_medium('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.',
352 [r".*: warning: \[OverridesGuiceInjectableMethod\] .+"]),
353 java_medium('Detects `/* name= */`-style comments on actual parameters where the name doesn\'t match the formal parameter',
354 [r".*: warning: \[ParameterName\] .+"]),
355 java_medium('Preconditions only accepts the %s placeholder in error message strings',
356 [r".*: warning: \[PreconditionsInvalidPlaceholder\] .+"]),
357 java_medium('Passing a primitive array to a varargs method is usually wrong',
358 [r".*: warning: \[PrimitiveArrayPassedToVarargsMethod\] .+"]),
359 java_medium('A field on a protocol buffer was set twice in the same chained expression.',
360 [r".*: warning: \[ProtoRedundantSet\] .+"]),
361 java_medium('Protos should not be used as a key to a map, in a set, or in a contains method on a descendant of a collection. Protos have non deterministic ordering and proto equality is deep, which is a performance issue.',
362 [r".*: warning: \[ProtosAsKeyOfSetOrMap\] .+"]),
363 java_medium('BugChecker has incorrect ProvidesFix tag, please update',
364 [r".*: warning: \[ProvidesFix\] .+"]),
365 java_medium('Qualifiers/Scope annotations on @Inject methods don\'t have any effect. Move the qualifier annotation to the binding location.',
366 [r".*: warning: \[QualifierOrScopeOnInjectMethod\] .+"]),
367 java_medium('Injection frameworks currently don\'t understand Qualifiers in TYPE_PARAMETER or TYPE_USE contexts.',
368 [r".*: warning: \[QualifierWithTypeUse\] .+"]),
369 java_medium('reachabilityFence should always be called inside a finally block',
370 [r".*: warning: \[ReachabilityFenceUsage\] .+"]),
371 java_medium('Thrown exception is a subtype of another',
372 [r".*: warning: \[RedundantThrows\] .+"]),
373 java_medium('Comparison using reference equality instead of value equality',
374 [r".*: warning: \[ReferenceEquality\] .+"]),
375 java_medium('This annotation is missing required modifiers as specified by its @RequiredModifiers annotation',
376 [r".*: warning: \[RequiredModifiers\] .+"]),
377 java_medium('Void methods should not have a @return tag.',
378 [r".*: warning: \[ReturnFromVoid\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800379 java_medium('SAM-compatible parameters should be last',
380 [r".*\.java:.*: warning: .+ \[SamShouldBeLast\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800381 java_medium(u'Prefer the short-circuiting boolean operators \u0026\u0026 and || to \u0026 and |.',
382 [r".*: warning: \[ShortCircuitBoolean\] .+"]),
383 java_medium('Writes to static fields should not be guarded by instance locks',
384 [r".*: warning: \[StaticGuardedByInstance\] .+"]),
385 java_medium('A static variable or method should be qualified with a class name, not expression',
386 [r".*: warning: \[StaticQualifiedUsingExpression\] .+"]),
387 java_medium('Streams that encapsulate a closeable resource should be closed using try-with-resources',
388 [r".*: warning: \[StreamResourceLeak\] .+"]),
389 java_medium('String comparison using reference equality instead of value equality',
390 [r".*: warning: \[StringEquality\] .+"]),
391 java_medium('String.split(String) has surprising behavior',
392 [r".*: warning: \[StringSplitter\] .+"]),
393 java_medium('SWIG generated code that can\'t call a C++ destructor will leak memory',
394 [r".*: warning: \[SwigMemoryLeak\] .+"]),
395 java_medium('Synchronizing on non-final fields is not safe: if the field is ever updated, different threads may end up locking on different objects.',
396 [r".*: warning: \[SynchronizeOnNonFinalField\] .+"]),
397 java_medium('Code that contains System.exit() is untestable.',
398 [r".*: warning: \[SystemExitOutsideMain\] .+"]),
399 java_medium('Using @Test(expected=...) is discouraged, since the test will pass if *any* statement in the test method throws the expected exception',
400 [r".*: warning: \[TestExceptionChecker\] .+"]),
401 java_medium('Thread.join needs to be surrounded by a loop until it succeeds, as in Uninterruptibles.joinUninterruptibly.',
402 [r".*: warning: \[ThreadJoinLoop\] .+"]),
403 java_medium('ThreadLocals should be stored in static fields',
404 [r".*: warning: \[ThreadLocalUsage\] .+"]),
405 java_medium('Relying on the thread scheduler is discouraged; see Effective Java Item 72 (2nd edition) / 84 (3rd edition).',
406 [r".*: warning: \[ThreadPriorityCheck\] .+"]),
407 java_medium('Three-letter time zone identifiers are deprecated, may be ambiguous, and might not do what you intend; the full IANA time zone ID should be used instead.',
408 [r".*: warning: \[ThreeLetterTimeZoneID\] .+"]),
409 java_medium('An implementation of Object.toString() should never return null.',
410 [r".*: warning: \[ToStringReturnsNull\] .+"]),
411 java_medium('The actual and expected values appear to be swapped, which results in poor assertion failure messages. The actual value should come first.',
412 [r".*: warning: \[TruthAssertExpected\] .+"]),
413 java_medium('Truth Library assert is called on a constant.',
414 [r".*: warning: \[TruthConstantAsserts\] .+"]),
415 java_medium('Argument is not compatible with the subject\'s type.',
416 [r".*: warning: \[TruthIncompatibleType\] .+"]),
417 java_medium('Type parameter declaration shadows another named type',
418 [r".*: warning: \[TypeNameShadowing\] .+"]),
419 java_medium('Type parameter declaration overrides another type parameter already declared',
420 [r".*: warning: \[TypeParameterShadowing\] .+"]),
421 java_medium('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.',
422 [r".*: warning: \[TypeParameterUnusedInFormals\] .+"]),
423 java_medium('Avoid hash-based containers of java.net.URL--the containers rely on equals() and hashCode(), which cause java.net.URL to make blocking internet connections.',
424 [r".*: warning: \[URLEqualsHashCode\] .+"]),
425 java_medium('Collection, Iterable, Multimap, and Queue do not have well-defined equals behavior',
426 [r".*: warning: \[UndefinedEquals\] .+"]),
427 java_medium('Switch handles all enum values: an explicit default case is unnecessary and defeats error checking for non-exhaustive switches.',
428 [r".*: warning: \[UnnecessaryDefaultInEnumSwitch\] .+"]),
429 java_medium('Unnecessary use of grouping parentheses',
430 [r".*: warning: \[UnnecessaryParentheses\] .+"]),
431 java_medium('Finalizer may run before native code finishes execution',
432 [r".*: warning: \[UnsafeFinalization\] .+"]),
433 java_medium('Prefer `asSubclass` instead of casting the result of `newInstance`, to detect classes of incorrect type before invoking their constructors.This way, if the class is of the incorrect type,it will throw an exception before invoking its constructor.',
434 [r".*: warning: \[UnsafeReflectiveConstructionCast\] .+"]),
435 java_medium('Unsynchronized method overrides a synchronized method.',
436 [r".*: warning: \[UnsynchronizedOverridesSynchronized\] .+"]),
437 java_medium('Unused.',
438 [r".*: warning: \[Unused\] .+"]),
439 java_medium('This catch block catches an exception and re-throws another, but swallows the caught exception rather than setting it as a cause. This can make debugging harder.',
440 [r".*: warning: \[UnusedException\] .+"]),
441 java_medium('Java assert is used in test. For testing purposes Assert.* matchers should be used.',
442 [r".*: warning: \[UseCorrectAssertInTests\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800443 java_medium('UserHandle',
444 [r".*\.java:.*: warning: .+ \[UserHandle\]$"]),
445 java_medium('UserHandleName',
446 [r".*\.java:.*: warning: .+ \[UserHandleName\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800447 java_medium('Non-constant variable missing @Var annotation',
448 [r".*: warning: \[Var\] .+"]),
449 java_medium('variableName and type with the same name would refer to the static field instead of the class',
450 [r".*: warning: \[VariableNameSameAsType\] .+"]),
451 java_medium('Because of spurious wakeups, Object.wait() and Condition.await() must always be called in a loop',
452 [r".*: warning: \[WaitNotInLoop\] .+"]),
453 java_medium('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.',
454 [r".*: warning: \[WakelockReleasedDangerously\] .+"]),
455 java_high('AndroidInjection.inject() should always be invoked before calling super.lifecycleMethod()',
456 [r".*: warning: \[AndroidInjectionBeforeSuper\] .+"]),
457 java_high('Use of class, field, or method that is not compatible with legacy Android devices',
458 [r".*: warning: \[AndroidJdkLibsChecker\] .+"]),
459 java_high('Reference equality used to compare arrays',
460 [r".*: warning: \[ArrayEquals\] .+"]),
461 java_high('Arrays.fill(Object[], Object) called with incompatible types.',
462 [r".*: warning: \[ArrayFillIncompatibleType\] .+"]),
463 java_high('hashcode method on array does not hash array contents',
464 [r".*: warning: \[ArrayHashCode\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800465 java_high('ArrayReturn',
466 [r".*\.java:.*: warning: .+ \[ArrayReturn\]$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800467 java_high('Calling toString on an array does not provide useful information',
468 [r".*: warning: \[ArrayToString\] .+"]),
469 java_high('Arrays.asList does not autobox primitive arrays, as one might expect.',
470 [r".*: warning: \[ArraysAsListPrimitiveArray\] .+"]),
471 java_high('@AssistedInject and @Inject cannot be used on the same constructor.',
472 [r".*: warning: \[AssistedInjectAndInjectOnSameConstructor\] .+"]),
473 java_high('AsyncCallable should not return a null Future, only a Future whose result is null.',
474 [r".*: warning: \[AsyncCallableReturnsNull\] .+"]),
475 java_high('AsyncFunction should not return a null Future, only a Future whose result is null.',
476 [r".*: warning: \[AsyncFunctionReturnsNull\] .+"]),
477 java_high('@AutoFactory and @Inject should not be used in the same type.',
478 [r".*: warning: \[AutoFactoryAtInject\] .+"]),
479 java_high('Arguments to AutoValue constructor are in the wrong order',
480 [r".*: warning: \[AutoValueConstructorOrderChecker\] .+"]),
481 java_high('Shift by an amount that is out of range',
482 [r".*: warning: \[BadShiftAmount\] .+"]),
483 java_high('Object serialized in Bundle may have been flattened to base type.',
484 [r".*: warning: \[BundleDeserializationCast\] .+"]),
485 java_high('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.',
486 [r".*: warning: \[ChainingConstructorIgnoresParameter\] .+"]),
487 java_high('Ignored return value of method that is annotated with @CheckReturnValue',
488 [r".*: warning: \[CheckReturnValue\] .+"]),
489 java_high('The source file name should match the name of the top-level class it contains',
490 [r".*: warning: \[ClassName\] .+"]),
491 java_high('Incompatible type as argument to Object-accepting Java collections method',
492 [r".*: warning: \[CollectionIncompatibleType\] .+"]),
493 java_high(u'Implementing \'Comparable\u003cT>\' where T is not compatible with the implementing class.',
494 [r".*: warning: \[ComparableType\] .+"]),
495 java_high('this == null is always false, this != null is always true',
496 [r".*: warning: \[ComparingThisWithNull\] .+"]),
497 java_high('This comparison method violates the contract',
498 [r".*: warning: \[ComparisonContractViolated\] .+"]),
499 java_high('Comparison to value that is out of range for the compared type',
500 [r".*: warning: \[ComparisonOutOfRange\] .+"]),
501 java_high('@CompatibleWith\'s value is not a type argument.',
502 [r".*: warning: \[CompatibleWithAnnotationMisuse\] .+"]),
503 java_high('Non-compile-time constant expression passed to parameter with @CompileTimeConstant type annotation.',
504 [r".*: warning: \[CompileTimeConstant\] .+"]),
505 java_high('Non-trivial compile time constant boolean expressions shouldn\'t be used.',
506 [r".*: warning: \[ComplexBooleanConstant\] .+"]),
507 java_high('A conditional expression with numeric operands of differing types will perform binary numeric promotion of the operands; when these operands are of reference types, the expression\'s result may not be of the expected type.',
508 [r".*: warning: \[ConditionalExpressionNumericPromotion\] .+"]),
509 java_high('Compile-time constant expression overflows',
510 [r".*: warning: \[ConstantOverflow\] .+"]),
511 java_high('Dagger @Provides methods may not return null unless annotated with @Nullable',
512 [r".*: warning: \[DaggerProvidesNull\] .+"]),
513 java_high('Exception created but not thrown',
514 [r".*: warning: \[DeadException\] .+"]),
515 java_high('Thread created but not started',
516 [r".*: warning: \[DeadThread\] .+"]),
517 java_high('Deprecated item is not annotated with @Deprecated',
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800518 [r".*\.java:.*: warning: \[.*\] .+ is not annotated with @Deprecated$"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800519 java_high('Division by integer literal zero',
520 [r".*: warning: \[DivZero\] .+"]),
521 java_high('This method should not be called.',
522 [r".*: warning: \[DoNotCall\] .+"]),
523 java_high('Empty statement after if',
524 [r".*: warning: \[EmptyIf\] .+"]),
525 java_high('== NaN always returns false; use the isNaN methods instead',
526 [r".*: warning: \[EqualsNaN\] .+"]),
527 java_high('== must be used in equals method to check equality to itself or an infinite loop will occur.',
528 [r".*: warning: \[EqualsReference\] .+"]),
529 java_high('Comparing different pairs of fields/getters in an equals implementation is probably a mistake.',
530 [r".*: warning: \[EqualsWrongThing\] .+"]),
531 java_high('Method annotated @ForOverride must be protected or package-private and only invoked from declaring class, or from an override of the method',
532 [r".*: warning: \[ForOverride\] .+"]),
533 java_high('Invalid printf-style format string',
534 [r".*: warning: \[FormatString\] .+"]),
535 java_high('Invalid format string passed to formatting method.',
536 [r".*: warning: \[FormatStringAnnotation\] .+"]),
537 java_high('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.',
538 [r".*: warning: \[FunctionalInterfaceMethodChanged\] .+"]),
539 java_high('Futures.getChecked requires a checked exception type with a standard constructor.',
540 [r".*: warning: \[FuturesGetCheckedIllegalExceptionType\] .+"]),
541 java_high('DoubleMath.fuzzyEquals should never be used in an Object.equals() method',
542 [r".*: warning: \[FuzzyEqualsShouldNotBeUsedInEqualsMethod\] .+"]),
543 java_high('Calling getClass() on an annotation may return a proxy class',
544 [r".*: warning: \[GetClassOnAnnotation\] .+"]),
545 java_high('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',
546 [r".*: warning: \[GetClassOnClass\] .+"]),
547 java_high('Checks for unguarded accesses to fields and methods with @GuardedBy annotations',
548 [r".*: warning: \[GuardedBy\] .+"]),
549 java_high('Scope annotation on implementation class of AssistedInject factory is not allowed',
550 [r".*: warning: \[GuiceAssistedInjectScoping\] .+"]),
551 java_high('A constructor cannot have two @Assisted parameters of the same type unless they are disambiguated with named @Assisted annotations.',
552 [r".*: warning: \[GuiceAssistedParameters\] .+"]),
553 java_high('Although Guice allows injecting final fields, doing so is disallowed because the injected value may not be visible to other threads.',
554 [r".*: warning: \[GuiceInjectOnFinalField\] .+"]),
555 java_high('contains() is a legacy method that is equivalent to containsValue()',
556 [r".*: warning: \[HashtableContains\] .+"]),
557 java_high('A binary expression where both operands are the same is usually incorrect.',
558 [r".*: warning: \[IdentityBinaryExpression\] .+"]),
559 java_high('Type declaration annotated with @Immutable is not immutable',
560 [r".*: warning: \[Immutable\] .+"]),
561 java_high('Modifying an immutable collection is guaranteed to throw an exception and leave the collection unmodified',
562 [r".*: warning: \[ImmutableModification\] .+"]),
563 java_high('Passing argument to a generic method with an incompatible type.',
564 [r".*: warning: \[IncompatibleArgumentType\] .+"]),
565 java_high('The first argument to indexOf is a Unicode code point, and the second is the index to start the search from',
566 [r".*: warning: \[IndexOfChar\] .+"]),
567 java_high('Conditional expression in varargs call contains array and non-array arguments',
568 [r".*: warning: \[InexactVarargsConditional\] .+"]),
569 java_high('This method always recurses, and will cause a StackOverflowError',
570 [r".*: warning: \[InfiniteRecursion\] .+"]),
571 java_high('A scoping annotation\'s Target should include TYPE and METHOD.',
572 [r".*: warning: \[InjectInvalidTargetingOnScopingAnnotation\] .+"]),
573 java_high('Using more than one qualifier annotation on the same element is not allowed.',
574 [r".*: warning: \[InjectMoreThanOneQualifier\] .+"]),
575 java_high('A class can be annotated with at most one scope annotation.',
576 [r".*: warning: \[InjectMoreThanOneScopeAnnotationOnClass\] .+"]),
577 java_high('Members shouldn\'t be annotated with @Inject if constructor is already annotated @Inject',
578 [r".*: warning: \[InjectOnMemberAndConstructor\] .+"]),
579 java_high('Scope annotation on an interface or abstact class is not allowed',
580 [r".*: warning: \[InjectScopeAnnotationOnInterfaceOrAbstractClass\] .+"]),
581 java_high('Scoping and qualifier annotations must have runtime retention.',
582 [r".*: warning: \[InjectScopeOrQualifierAnnotationRetention\] .+"]),
583 java_high('Injected constructors cannot be optional nor have binding annotations',
584 [r".*: warning: \[InjectedConstructorAnnotations\] .+"]),
585 java_high('A standard cryptographic operation is used in a mode that is prone to vulnerabilities',
586 [r".*: warning: \[InsecureCryptoUsage\] .+"]),
587 java_high('Invalid syntax used for a regular expression',
588 [r".*: warning: \[InvalidPatternSyntax\] .+"]),
589 java_high('Invalid time zone identifier. TimeZone.getTimeZone(String) will silently return GMT instead of the time zone you intended.',
590 [r".*: warning: \[InvalidTimeZoneID\] .+"]),
591 java_high('The argument to Class#isInstance(Object) should not be a Class',
592 [r".*: warning: \[IsInstanceOfClass\] .+"]),
593 java_high('Log tag too long, cannot exceed 23 characters.',
594 [r".*: warning: \[IsLoggableTagLength\] .+"]),
595 java_high(u'Path implements Iterable\u003cPath>; prefer Collection\u003cPath> for clarity',
596 [r".*: warning: \[IterablePathParameter\] .+"]),
597 java_high('jMock tests must have a @RunWith(JMock.class) annotation, or the Mockery field must have a @Rule JUnit annotation',
598 [r".*: warning: \[JMockTestWithoutRunWithOrRuleAnnotation\] .+"]),
599 java_high('Test method will not be run; please correct method signature (Should be public, non-static, and method name should begin with "test").',
600 [r".*: warning: \[JUnit3TestNotRun\] .+"]),
601 java_high('This method should be static',
602 [r".*: warning: \[JUnit4ClassAnnotationNonStatic\] .+"]),
603 java_high('setUp() method will not be run; please add JUnit\'s @Before annotation',
604 [r".*: warning: \[JUnit4SetUpNotRun\] .+"]),
605 java_high('tearDown() method will not be run; please add JUnit\'s @After annotation',
606 [r".*: warning: \[JUnit4TearDownNotRun\] .+"]),
607 java_high('This looks like a test method but is not run; please add @Test and @Ignore, or, if this is a helper method, reduce its visibility.',
608 [r".*: warning: \[JUnit4TestNotRun\] .+"]),
609 java_high('An object is tested for reference equality to itself using JUnit library.',
610 [r".*: warning: \[JUnitAssertSameCheck\] .+"]),
611 java_high('Use of class, field, or method that is not compatible with JDK 7',
612 [r".*: warning: \[Java7ApiChecker\] .+"]),
613 java_high('Abstract and default methods are not injectable with javax.inject.Inject',
614 [r".*: warning: \[JavaxInjectOnAbstractMethod\] .+"]),
615 java_high('@javax.inject.Inject cannot be put on a final field.',
616 [r".*: warning: \[JavaxInjectOnFinalField\] .+"]),
617 java_high('This pattern will silently corrupt certain byte sequences from the serialized protocol message. Use ByteString or byte[] directly',
618 [r".*: warning: \[LiteByteStringUtf8\] .+"]),
619 java_high('This method does not acquire the locks specified by its @LockMethod annotation',
620 [r".*: warning: \[LockMethodChecker\] .+"]),
621 java_high('Prefer \'L\' to \'l\' for the suffix to long literals',
622 [r".*: warning: \[LongLiteralLowerCaseSuffix\] .+"]),
623 java_high('Loop condition is never modified in loop body.',
624 [r".*: warning: \[LoopConditionChecker\] .+"]),
625 java_high('Math.round(Integer) results in truncation',
626 [r".*: warning: \[MathRoundIntLong\] .+"]),
627 java_high('Certain resources in `android.R.string` have names that do not match their content',
628 [r".*: warning: \[MislabeledAndroidString\] .+"]),
629 java_high('Overriding method is missing a call to overridden super method',
630 [r".*: warning: \[MissingSuperCall\] .+"]),
631 java_high('A terminating method call is required for a test helper to have any effect.',
632 [r".*: warning: \[MissingTestCall\] .+"]),
633 java_high('Use of "YYYY" (week year) in a date pattern without "ww" (week in year). You probably meant to use "yyyy" (year) instead.',
634 [r".*: warning: \[MisusedWeekYear\] .+"]),
635 java_high('A bug in Mockito will cause this test to fail at runtime with a ClassCastException',
636 [r".*: warning: \[MockitoCast\] .+"]),
637 java_high('Missing method call for verify(mock) here',
638 [r".*: warning: \[MockitoUsage\] .+"]),
639 java_high('Using a collection function with itself as the argument.',
640 [r".*: warning: \[ModifyingCollectionWithItself\] .+"]),
641 java_high('This class has more than one @Inject-annotated constructor. Please remove the @Inject annotation from all but one of them.',
642 [r".*: warning: \[MoreThanOneInjectableConstructor\] .+"]),
643 java_high('The result of this method must be closed.',
644 [r".*: warning: \[MustBeClosedChecker\] .+"]),
645 java_high('The first argument to nCopies is the number of copies, and the second is the item to copy',
646 [r".*: warning: \[NCopiesOfChar\] .+"]),
647 java_high('@NoAllocation was specified on this method, but something was found that would trigger an allocation',
648 [r".*: warning: \[NoAllocation\] .+"]),
649 java_high('Static import of type uses non-canonical name',
650 [r".*: warning: \[NonCanonicalStaticImport\] .+"]),
651 java_high('@CompileTimeConstant parameters should be final or effectively final',
652 [r".*: warning: \[NonFinalCompileTimeConstant\] .+"]),
653 java_high('Calling getAnnotation on an annotation that is not retained at runtime.',
654 [r".*: warning: \[NonRuntimeAnnotation\] .+"]),
655 java_high('This conditional expression may evaluate to null, which will result in an NPE when the result is unboxed.',
656 [r".*: warning: \[NullTernary\] .+"]),
657 java_high('Numeric comparison using reference equality instead of value equality',
658 [r".*: warning: \[NumericEquality\] .+"]),
659 java_high('Comparison using reference equality instead of value equality',
660 [r".*: warning: \[OptionalEquality\] .+"]),
661 java_high('Annotations cannot be both Scope annotations and Qualifier annotations: this causes confusion when trying to use them.',
662 [r".*: warning: \[OverlappingQualifierAndScopeAnnotation\] .+"]),
663 java_high('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.',
664 [r".*: warning: \[OverridesJavaxInjectableMethod\] .+"]),
665 java_high('Declaring types inside package-info.java files is very bad form',
666 [r".*: warning: \[PackageInfo\] .+"]),
667 java_high('Method parameter has wrong package',
668 [r".*: warning: \[ParameterPackage\] .+"]),
669 java_high('Detects classes which implement Parcelable but don\'t have CREATOR',
670 [r".*: warning: \[ParcelableCreator\] .+"]),
671 java_high('Literal passed as first argument to Preconditions.checkNotNull() can never be null',
672 [r".*: warning: \[PreconditionsCheckNotNull\] .+"]),
673 java_high('First argument to `Preconditions.checkNotNull()` is a primitive rather than an object reference',
674 [r".*: warning: \[PreconditionsCheckNotNullPrimitive\] .+"]),
675 java_high('Using ::equals or ::isInstance as an incompatible Predicate; the predicate will always return false',
676 [r".*: warning: \[PredicateIncompatibleType\] .+"]),
677 java_high('Access to a private protocol buffer field is forbidden. This protocol buffer carries a security contract, and can only be created using an approved library. Direct access to the fields is forbidden.',
678 [r".*: warning: \[PrivateSecurityContractProtoAccess\] .+"]),
679 java_high('Protobuf fields cannot be null.',
680 [r".*: warning: \[ProtoFieldNullComparison\] .+"]),
681 java_high('Comparing protobuf fields of type String using reference equality',
682 [r".*: warning: \[ProtoStringFieldReferenceEquality\] .+"]),
683 java_high('To get the tag number of a protocol buffer enum, use getNumber() instead.',
684 [r".*: warning: \[ProtocolBufferOrdinal\] .+"]),
685 java_high('@Provides methods need to be declared in a Module to have any effect.',
686 [r".*: warning: \[ProvidesMethodOutsideOfModule\] .+"]),
687 java_high('Casting a random number in the range [0.0, 1.0) to an integer or long always results in 0.',
688 [r".*: warning: \[RandomCast\] .+"]),
689 java_high('Use Random.nextInt(int). Random.nextInt() % n can have negative results',
690 [r".*: warning: \[RandomModInteger\] .+"]),
691 java_high('Return value of android.graphics.Rect.intersect() must be checked',
692 [r".*: warning: \[RectIntersectReturnValueIgnored\] .+"]),
693 java_high('Use of method or class annotated with @RestrictTo',
694 [r".*: warning: \[RestrictTo\] .+"]),
695 java_high(' Check for non-whitelisted callers to RestrictedApiChecker.',
696 [r".*: warning: \[RestrictedApiChecker\] .+"]),
697 java_high('Return value of this method must be used',
698 [r".*: warning: \[ReturnValueIgnored\] .+"]),
699 java_high('Variable assigned to itself',
700 [r".*: warning: \[SelfAssignment\] .+"]),
701 java_high('An object is compared to itself',
702 [r".*: warning: \[SelfComparison\] .+"]),
703 java_high('Testing an object for equality with itself will always be true.',
704 [r".*: warning: \[SelfEquals\] .+"]),
705 java_high('This method must be called with an even number of arguments.',
706 [r".*: warning: \[ShouldHaveEvenArgs\] .+"]),
707 java_high('Comparison of a size >= 0 is always true, did you intend to check for non-emptiness?',
708 [r".*: warning: \[SizeGreaterThanOrEqualsZero\] .+"]),
709 java_high('Static and default interface methods are not natively supported on older Android devices. ',
710 [r".*: warning: \[StaticOrDefaultInterfaceMethod\] .+"]),
711 java_high('Calling toString on a Stream does not provide useful information',
712 [r".*: warning: \[StreamToString\] .+"]),
713 java_high('StringBuilder does not have a char constructor; this invokes the int constructor.',
714 [r".*: warning: \[StringBuilderInitWithChar\] .+"]),
715 java_high('String.substring(0) returns the original String',
716 [r".*: warning: \[SubstringOfZero\] .+"]),
717 java_high('Suppressing "deprecated" is probably a typo for "deprecation"',
718 [r".*: warning: \[SuppressWarningsDeprecated\] .+"]),
719 java_high('throwIfUnchecked(knownCheckedException) is a no-op.',
720 [r".*: warning: \[ThrowIfUncheckedKnownChecked\] .+"]),
721 java_high('Throwing \'null\' always results in a NullPointerException being thrown.',
722 [r".*: warning: \[ThrowNull\] .+"]),
723 java_high('isEqualTo should not be used to test an object for equality with itself; the assertion will never fail.',
724 [r".*: warning: \[TruthSelfEquals\] .+"]),
725 java_high('Catching Throwable/Error masks failures from fail() or assert*() in the try block',
726 [r".*: warning: \[TryFailThrowable\] .+"]),
727 java_high('Type parameter used as type qualifier',
728 [r".*: warning: \[TypeParameterQualifier\] .+"]),
729 java_high('This method does not acquire the locks specified by its @UnlockMethod annotation',
730 [r".*: warning: \[UnlockMethod\] .+"]),
731 java_high('Non-generic methods should not be invoked with type arguments',
732 [r".*: warning: \[UnnecessaryTypeArgument\] .+"]),
733 java_high('Instance created but never used',
734 [r".*: warning: \[UnusedAnonymousClass\] .+"]),
735 java_high('Collection is modified in place, but the result is not used',
736 [r".*: warning: \[UnusedCollectionModifiedInPlace\] .+"]),
737 java_high('`var` should not be used as a type name.',
738 [r".*: warning: \[VarTypeName\] .+"]),
Chih-Hung Hsieha9f77462020-01-06 12:02:27 -0800739 # Other javac tool warnings
740 java_medium('addNdkApiCoverage failed to getPackage',
741 [r".*: warning: addNdkApiCoverage failed to getPackage"]),
742 java_medium('Supported version from annotation processor',
743 [r".*: warning: Supported source version .+ from annotation processor"]),
Chih-Hung Hsieh888d1432019-12-09 19:32:03 -0800744]