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