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