1JAVA_VERSION_OPTS = [] 2 3# A more robust set of lint and errorprone checks when building 4# Java source to improve code consistency. 5 6XLINT_OPTS = [ 7 "-Werror", 8 "-Xlint:all", 9 "-Xlint:-processing", 10 "-Xlint:-serial", 11 "-Xlint:-try", 12 "-Xlint:-classfile", # see b/32750402, go/javac-warnings#classfile 13 "-Xlint:-options", # see b/195079247 14] 15 16# The bazel errorprone plugin currently only enables default errorChecks 17# https://github.com/bazelbuild/bazel/blob/97975603e5ff2247e6bb352e3afd27fea38f108d/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorPronePlugin.java#L52 18# 19# Default errorChecks are errorprone checkers listed under ENABLED_ERRORS at 20# https://github.com/google/error-prone/blob/c6f24bc387989158d99af28e7ae86755e56c5f38/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java#L273 21# 22# Here we enable all available errorprone checks to converge on a consistent 23# code style. 24# https://github.com/google/error-prone/blob/c6f24bc387989158d99af28e7ae86755e56c5f38/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java#L260 25 26# This list is from ENABLED_WARNINGS in 27# com/google/errorprone/scanner/BuiltInCheckerSuppliers.java 28EP_ENABLED_WARNINGS = [ 29 "-Xep:AmbiguousMethodReference:ERROR", 30 "-Xep:ArgumentSelectionDefectChecker:ERROR", 31 "-Xep:AssertEqualsArgumentOrderChecker:ERROR", 32 "-Xep:BadAnnotationImplementation:ERROR", 33 "-Xep:BadComparable:ERROR", 34 "-Xep:BoxedPrimitiveConstructor:ERROR", 35 "-Xep:CannotMockFinalClass:ERROR", 36 "-Xep:ClassCanBeStatic:ERROR", 37 "-Xep:ClassNewInstance:ERROR", 38 "-Xep:DefaultCharset:ERROR", 39 "-Xep:DoubleCheckedLocking:ERROR", 40 "-Xep:ElementsCountedInLoop:ERROR", 41 "-Xep:EqualsHashCode:ERROR", 42 "-Xep:EqualsIncompatibleType:ERROR", 43 "-Xep:Finally:ERROR", 44 "-Xep:FloatingPointLiteralPrecision:ERROR", 45 "-Xep:FragmentInjection:ERROR", 46 "-Xep:FragmentNotInstantiable:ERROR", 47 "-Xep:FunctionalInterfaceClash:ERROR", 48 "-Xep:FutureReturnValueIgnored:ERROR", 49 "-Xep:GetClassOnEnum:ERROR", 50 "-Xep:ImmutableAnnotationChecker:ERROR", 51 "-Xep:ImmutableEnumChecker:ERROR", 52 "-Xep:IncompatibleModifiers:ERROR", 53 "-Xep:InjectOnConstructorOfAbstractClass:ERROR", 54 "-Xep:InputStreamSlowMultibyteRead:ERROR", 55 "-Xep:IterableAndIterator:ERROR", 56 "-Xep:JavaLangClash:ERROR", 57 "-Xep:JUnit3FloatingPointComparisonWithoutDelta:ERROR", 58 "-Xep:JUnitAmbiguousTestClass:ERROR", 59 "-Xep:LiteralClassName:ERROR", 60 "-Xep:LogicalAssignment:ERROR", 61 "-Xep:MissingFail:ERROR", 62 "-Xep:MissingOverride:ERROR", 63 "-Xep:MutableConstantField:ERROR", 64 "-Xep:NamedParameters:ERROR", 65 "-Xep:NarrowingCompoundAssignment:ERROR", 66 "-Xep:NonAtomicVolatileUpdate:ERROR", 67 "-Xep:NonOverridingEquals:ERROR", 68 "-Xep:NullableConstructor:ERROR", 69 "-Xep:NullablePrimitive:ERROR", 70 "-Xep:NullableVoid:ERROR", 71 "-Xep:OperatorPrecedence:ERROR", 72 "-Xep:OverridesGuiceInjectableMethod:ERROR", 73 "-Xep:PreconditionsInvalidPlaceholder:ERROR", 74 "-Xep:ProtoFieldPreconditionsCheckNotNull:ERROR", 75 "-Xep:ReferenceEquality:ERROR", 76 "-Xep:RequiredModifiers:ERROR", 77 "-Xep:ShortCircuitBoolean:ERROR", 78 "-Xep:SimpleDateFormatConstant:ERROR", 79 "-Xep:StaticGuardedByInstance:ERROR", 80 "-Xep:SynchronizeOnNonFinalField:ERROR", 81 "-Xep:TruthConstantAsserts:ERROR", 82 "-Xep:TypeParameterShadowing:ERROR", 83 "-Xep:TypeParameterUnusedInFormals:ERROR", 84 "-Xep:UnsynchronizedOverridesSynchronized:ERROR", 85 "-Xep:URLEqualsHashCode:ERROR", 86 "-Xep:WaitNotInLoop:ERROR", 87] 88 89# This list is from DISABLED_CHECKS in 90# com/google/errorprone/scanner/BuiltInCheckerSuppliers.java 91EP_DISABLED_CHECKS = [ 92 "-Xep:AutoFactoryAtInject:ERROR", 93 "-Xep:AssertFalse:ERROR", 94 "-Xep:AssistedInjectAndInjectOnConstructors:ERROR", 95 "-Xep:AssistedInjectAndInjectOnSameConstructor:ERROR", 96 "-Xep:BigDecimalLiteralDouble:ERROR", 97 "-Xep:BindingToUnqualifiedCommonType:ERROR", 98 "-Xep:ClassName:ERROR", 99 "-Xep:ComparisonContractViolated:ERROR", 100 "-Xep:ConstantField:ERROR", 101 "-Xep:ConstructorInvokesOverridable:ERROR", 102 # False positives, disabled 103 # "-Xep:ConstructorLeaksThis:ERROR", 104 "-Xep:DepAnn:ERROR", 105 "-Xep:DivZero:ERROR", 106 "-Xep:EmptyIfStatement:ERROR", 107 "-Xep:EmptySetMultibindingContributions:ERROR", 108 "-Xep:EmptyTopLevelDeclaration:ERROR", 109 "-Xep:ExpectedExceptionChecker:ERROR", 110 "-Xep:HardCodedSdCardPath:ERROR", 111 "-Xep:InjectedConstructorAnnotations:ERROR", 112 "-Xep:InsecureCipherMode:ERROR", 113 "-Xep:InvalidTargetingOnScopingAnnotation:ERROR", 114 "-Xep:IterablePathParameter:ERROR", 115 "-Xep:JMockTestWithoutRunWithOrRuleAnnotation:ERROR", 116 "-Xep:JavaxInjectOnFinalField:ERROR", 117 "-Xep:LockMethodChecker:ERROR", 118 "-Xep:LongLiteralLowerCaseSuffix:ERROR", 119 "-Xep:MethodCanBeStatic:ERROR", 120 "-Xep:MissingDefault:ERROR", 121 "-Xep:MixedArrayDimensions:ERROR", 122 "-Xep:MoreThanOneQualifier:ERROR", 123 "-Xep:MultiVariableDeclaration:ERROR", 124 "-Xep:MultipleTopLevelClasses:ERROR", 125 "-Xep:NoAllocationChecker:ERROR", 126 "-Xep:NonCanonicalStaticMemberImport:ERROR", 127 "-Xep:NumericEquality:ERROR", 128 "-Xep:PackageLocation:ERROR", 129 "-Xep:PrimitiveArrayPassedToVarargsMethod:ERROR", 130 "-Xep:PrivateConstructorForUtilityClass:ERROR", 131 "-Xep:PrivateConstructorForNoninstantiableModule:ERROR", 132 "-Xep:ProtoStringFieldReferenceEquality:ERROR", 133 "-Xep:QualifierOrScopeOnInjectMethod:ERROR", 134 "-Xep:QualifierWithTypeUse:ERROR", 135 "-Xep:RedundantThrows:ERROR", 136 "-Xep:RemoveUnusedImports:ERROR", 137 "-Xep:ScopeAnnotationOnInterfaceOrAbstractClass:ERROR", 138 "-Xep:ScopeOrQualifierAnnotationRetention:ERROR", 139 "-Xep:StaticQualifiedUsingExpression:ERROR", 140 "-Xep:StaticOrDefaultInterfaceMethod:ERROR", 141 "-Xep:StringEquality:ERROR", 142 "-Xep:TestExceptionChecker:ERROR", 143 # TODO: stylistic changes in code 144 # "-Xep:ThrowsUncheckedException:ERROR", 145 # "-Xep:UngroupedOverloads:ERROR", 146 "-Xep:UnlockMethodChecker:ERROR", 147 "-Xep:UnnecessaryDefaultInEnumSwitch:ERROR", 148 "-Xep:UnnecessaryStaticImport:ERROR", 149 "-Xep:UseBinds:ERROR", 150 "-Xep:VarChecker:ERROR", 151 "-Xep:WildcardImport:ERROR", 152 "-Xep:WrongParameterPackage:ERROR", 153] 154 155EP_OPTS = EP_ENABLED_WARNINGS + EP_DISABLED_CHECKS 156 157JAVACOPTS = JAVA_VERSION_OPTS + XLINT_OPTS + EP_OPTS 158