1// Copyright 2017 Google Inc. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package error_prone 16 17import ( 18 "android/soong/java/config" 19) 20 21func init() { 22 // These values are set into build/soong/java/config/config.go so that soong doesn't have any 23 // references to external/error_prone, which may not always exist. 24 config.ErrorProneClasspath = []string{ 25 "external/error_prone/error_prone/error_prone_core-2.36.0-with-dependencies.jar", 26 "external/error_prone/error_prone/error_prone_annotations-2.36.0.jar", 27 "external/error_prone/error_prone/error_prone_type_annotations-2.36.0.jar", 28 "external/error_prone/checkerframework/dataflow-errorprone-3.39.0.jar", 29 "external/error_prone/jFormatString/jFormatString-3.0.0.jar", 30 } 31 32 // The checks that are fatal to the build. 33 config.ErrorProneChecksError = []string{ 34 // Errorprone default severity ERROR 35 "-Xep:AndroidInjectionBeforeSuper:ERROR", 36 "-Xep:ArrayFillIncompatibleType:ERROR", 37 "-Xep:AsyncCallableReturnsNull:ERROR", 38 "-Xep:AsyncFunctionReturnsNull:ERROR", 39 "-Xep:AutoValueConstructorOrderChecker:ERROR", 40 "-Xep:BundleDeserializationCast:ERROR", 41 "-Xep:ChainingConstructorIgnoresParameter:ERROR", 42 "-Xep:CheckReturnValue:ERROR", 43 "-Xep:CollectionIncompatibleType:ERROR", 44 "-Xep:ComparingThisWithNull:ERROR", 45 "-Xep:ComparisonOutOfRange:ERROR", 46 "-Xep:CompatibleWithAnnotationMisuse:ERROR", 47 "-Xep:CompileTimeConstant:ERROR", 48 "-Xep:ConstantOverflow:ERROR", 49 "-Xep:DaggerProvidesNull:ERROR", 50 "-Xep:DeadException:ERROR", 51 "-Xep:DeadThread:ERROR", 52 "-Xep:DoNotCall:ERROR", 53 "-Xep:EqualsNaN:ERROR", 54 "-Xep:EqualsWrongThing:ERROR", 55 "-Xep:ErroneousThreadPoolConstructorChecker:ERROR", 56 "-Xep:ForOverride:ERROR", 57 "-Xep:FormatStringAnnotation:ERROR", 58 "-Xep:FunctionalInterfaceMethodChanged:ERROR", 59 "-Xep:FuturesGetCheckedIllegalExceptionType:ERROR", 60 "-Xep:GuiceAssistedInjectScoping:ERROR", 61 "-Xep:GuiceAssistedParameters:ERROR", 62 "-Xep:GuiceInjectOnFinalField:ERROR", 63 "-Xep:Immutable:ERROR", 64 "-Xep:IncompatibleArgumentType:ERROR", 65 "-Xep:IndexOfChar:ERROR", 66 "-Xep:InexactVarargsConditional:ERROR", 67 "-Xep:InfiniteRecursion:ERROR", 68 "-Xep:InjectMoreThanOneScopeAnnotationOnClass:ERROR", 69 "-Xep:InjectOnMemberAndConstructor:ERROR", 70 "-Xep:InvalidPatternSyntax:ERROR", 71 "-Xep:IsInstanceOfClass:ERROR", 72 "-Xep:JUnit3TestNotRun:ERROR", 73 "-Xep:JUnit4ClassAnnotationNonStatic:ERROR", 74 "-Xep:JUnit4SetUpNotRun:ERROR", 75 "-Xep:JUnit4TearDownNotRun:ERROR", 76 "-Xep:JUnitAssertSameCheck:ERROR", 77 "-Xep:JavaxInjectOnAbstractMethod:ERROR", 78 "-Xep:LiteByteStringUtf8:ERROR", 79 "-Xep:LoopConditionChecker:ERROR", 80 "-Xep:MissingTestCall:ERROR", 81 "-Xep:MockitoUsage:ERROR", 82 "-Xep:MoreThanOneInjectableConstructor:ERROR", 83 "-Xep:MustBeClosedChecker:ERROR", 84 "-Xep:NCopiesOfChar:ERROR", 85 "-Xep:NonCanonicalStaticImport:ERROR", 86 "-Xep:NonFinalCompileTimeConstant:ERROR", 87 "-Xep:OptionalEquality:ERROR", 88 "-Xep:OverlappingQualifierAndScopeAnnotation:ERROR", 89 "-Xep:PackageInfo:ERROR", 90 "-Xep:PrivateSecurityContractProtoAccess:ERROR", 91 "-Xep:ProtoFieldNullComparison:ERROR", 92 "-Xep:ProtoStringFieldReferenceEquality:ERROR", 93 "-Xep:ProvidesMethodOutsideOfModule:ERROR", 94 "-Xep:RandomCast:ERROR", 95 "-Xep:RestrictedApi:ERROR", 96 "-Xep:SelfAssignment:ERROR", 97 "-Xep:ShouldHaveEvenArgs:ERROR", 98 "-Xep:StreamToString:ERROR", 99 "-Xep:SubstringOfZero:ERROR", 100 "-Xep:SuppressWarningsDeprecated:ERROR", 101 "-Xep:ThrowIfUncheckedKnownChecked:ERROR", 102 "-Xep:ThrowNull:ERROR", 103 "-Xep:TruthSelfEquals:ERROR", 104 "-Xep:TypeParameterQualifier:ERROR", 105 "-Xep:UnnecessaryTypeArgument:ERROR", 106 "-Xep:UnusedAnonymousClass:ERROR", 107 "-Xep:VarTypeName:ERROR", 108 // Errorprone default severity WARNING 109 // Errorprone default severity SUGGESTION 110 } 111 112 // The checks that are not fatal to the build. 113 config.ErrorProneChecksWarning = []string{ 114 // Errorprone default severity ERROR 115 "-Xep:ComparisonOutOfRange:WARN", 116 "-Xep:EqualsHashCode:WARN", 117 "-Xep:GuardedBy:WARN", 118 "-Xep:ImmutableAnnotationChecker:WARN", 119 "-Xep:ImmutableEnumChecker:WARN", 120 "-Xep:IsLoggableTagLength:WARN", 121 "-Xep:JUnit4TestNotRun:WARN", 122 "-Xep:MissingSuperCall:WARN", 123 "-Xep:RectIntersectReturnValueIgnored:WARN", 124 "-Xep:SelfAssertion:WARN", 125 "-Xep:DuplicateBranches:WARN", 126 } 127 128 // The checks that are default-disabled 129 config.ErrorProneChecksDefaultDisabled = []string{} 130 131 config.ErrorProneChecksOff = []string{ 132 // We are not interested in Guava recommendations 133 // for String.split. 134 "-Xep:StringSplitter:OFF", 135 // b/117877739. 136 "-Xep:TruthAssertExpected:OFF", 137 // b/170172949 138 "-Xep:MissingOverride:OFF", 139 "-Xep:UnnecessaryParentheses:OFF", 140 // This triggers on android R classes, disable until we can ignore 141 // the generated R classes 142 "-Xep:MutablePublicArray:OFF", 143 // These checks crash 144 "-Xep:RethrowReflectiveOperationExceptionAsLinkageError:OFF", 145 "-Xep:InvalidLink:OFF", 146 // Commonly triggers for stubbed methods 147 "-Xep:DoNotCallSuggester:OFF", 148 "-Xep:MissingSummary:OFF", 149 // This check increates the `platformprotos` module's build 150 // time by ~15 minutes 151 "-Xep:SameNameButDifferent:OFF", 152 // Noisy and requires projects to add a dependency on errorprone annotations 153 "-Xep:CanIgnoreReturnValueSuggester:OFF", 154 // Data classes are encouraged to override toString(), but it is not a strict 155 // requirement. The warning is overtriggered when source depends on the API stubs, which 156 // may not include the toString() method. 157 "-Xep:ObjectToString:OFF", 158 // Disable the check which is introduced by the Java target 21 until modules 159 // can be fixed individually (b/377918299). 160 "-Xep:PatternMatchingInstanceof:OFF", 161 } 162 163 config.ErrorProneFlags = []string{ 164 "-Xdiags:verbose", 165 "-XDcompilePolicy=simple", 166 "-XDallowBetterNullChecks=false", 167 "-XDusePolyAttribution=true", 168 "-XDuseStrictMethodClashCheck=true", 169 "-XDuseStructuralMostSpecificResolution=true", 170 "-XDuseGraphInference=true", 171 "-XDandroidCompatible=true", 172 // https://github.com/google/error-prone/issues/4595#issuecomment-2424140062 173 "--should-stop=ifError=FLOW", 174 // As we emit errors as warnings, 175 // increase the warning limit. 176 "-Xmaxwarns 9999999", 177 178 // Extra flags needed by ErrorProne for OpenJDK9 from 179 // http://errorprone.info/docs/installation 180 "-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", 181 "-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", 182 "-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", 183 "-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED", 184 "-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED", 185 "-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED", 186 "-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", 187 "-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", 188 "-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", 189 "-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED", 190 } 191} 192