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