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