aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java/build_defs.bzl
blob: e1916ca4d9d6aa179e1a69451a5e981783560026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- Python -*-

# Pin to Java 1.7 to ensure broader compatibility for the Java bindings on
# Android. Note also that the android_library bazel rule currently enforces
# java 7
# https://github.com/bazelbuild/bazel/blob/6c1106b1a721516d3b3db54d2e1c31b44a76fbb1/src/main/java/com/google/devtools/build/lib/bazel/rules/android/BazelAndroidSemantics.java#L73

JAVA_VERSION_OPTS = [
    "-source 7 -target 7",
]

# A more robust set of lint and errorprone checks when building
# Java source to improve code consistency.

XLINT_OPTS = [
    "-Werror",
    "-Xlint:all",
    "-Xlint:-processing",
    "-Xlint:-serial",
    "-Xlint:-try",
    "-Xlint:-classfile", # see b/32750402, go/javac-warnings#classfile
]

# The bazel errorprone plugin currently only enables default errorChecks
# https://github.com/bazelbuild/bazel/blob/97975603e5ff2247e6bb352e3afd27fea38f108d/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/errorprone/ErrorPronePlugin.java#L52
#
# Default errorChecks are errorprone checkers listed under ENABLED_ERRORS at
# https://github.com/google/error-prone/blob/c6f24bc387989158d99af28e7ae86755e56c5f38/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java#L273
#
# Here we enable all available errorprone checks to converge on a consistent
# code style.
# https://github.com/google/error-prone/blob/c6f24bc387989158d99af28e7ae86755e56c5f38/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java#L260

# This list is from ENABLED_WARNINGS in
# com/google/errorprone/scanner/BuiltInCheckerSuppliers.java
EP_ENABLED_WARNINGS = [
    "-Xep:AmbiguousMethodReference:ERROR",
    "-Xep:ArgumentSelectionDefectChecker:ERROR",
    "-Xep:AssertEqualsArgumentOrderChecker:ERROR",
    "-Xep:BadAnnotationImplementation:ERROR",
    "-Xep:BadComparable:ERROR",
    "-Xep:BoxedPrimitiveConstructor:ERROR",
    "-Xep:CannotMockFinalClass:ERROR",
    "-Xep:ClassCanBeStatic:ERROR",
    "-Xep:ClassNewInstance:ERROR",
    "-Xep:DefaultCharset:ERROR",
    "-Xep:DoubleCheckedLocking:ERROR",
    "-Xep:ElementsCountedInLoop:ERROR",
    "-Xep:EqualsHashCode:ERROR",
    "-Xep:EqualsIncompatibleType:ERROR",
    "-Xep:Finally:ERROR",
    "-Xep:FloatingPointLiteralPrecision:ERROR",
    "-Xep:FragmentInjection:ERROR",
    "-Xep:FragmentNotInstantiable:ERROR",
    "-Xep:FunctionalInterfaceClash:ERROR",
    "-Xep:FutureReturnValueIgnored:ERROR",
    "-Xep:GetClassOnEnum:ERROR",
    "-Xep:ImmutableAnnotationChecker:ERROR",
    "-Xep:ImmutableEnumChecker:ERROR",
    "-Xep:IncompatibleModifiers:ERROR",
    "-Xep:InjectOnConstructorOfAbstractClass:ERROR",
    "-Xep:InputStreamSlowMultibyteRead:ERROR",
    "-Xep:IterableAndIterator:ERROR",
    "-Xep:JavaLangClash:ERROR",
    "-Xep:JUnit3FloatingPointComparisonWithoutDelta:ERROR",
    "-Xep:JUnitAmbiguousTestClass:ERROR",
    "-Xep:LiteralClassName:ERROR",
    "-Xep:LogicalAssignment:ERROR",
    "-Xep:MissingFail:ERROR",
    "-Xep:MissingOverride:ERROR",
    "-Xep:MutableConstantField:ERROR",
    "-Xep:NamedParameters:ERROR",
    "-Xep:NarrowingCompoundAssignment:ERROR",
    "-Xep:NonAtomicVolatileUpdate:ERROR",
    "-Xep:NonOverridingEquals:ERROR",
    "-Xep:NullableConstructor:ERROR",
    "-Xep:NullablePrimitive:ERROR",
    "-Xep:NullableVoid:ERROR",
    "-Xep:OperatorPrecedence:ERROR",
    "-Xep:OverridesGuiceInjectableMethod:ERROR",
    "-Xep:PreconditionsInvalidPlaceholder:ERROR",
    "-Xep:ProtoFieldPreconditionsCheckNotNull:ERROR",
    "-Xep:ReferenceEquality:ERROR",
    "-Xep:RequiredModifiers:ERROR",
    "-Xep:ShortCircuitBoolean:ERROR",
    "-Xep:SimpleDateFormatConstant:ERROR",
    "-Xep:StaticGuardedByInstance:ERROR",
    "-Xep:SynchronizeOnNonFinalField:ERROR",
    "-Xep:TruthConstantAsserts:ERROR",
    "-Xep:TypeParameterShadowing:ERROR",
    "-Xep:TypeParameterUnusedInFormals:ERROR",
    "-Xep:UnsynchronizedOverridesSynchronized:ERROR",
    "-Xep:URLEqualsHashCode:ERROR",
    "-Xep:WaitNotInLoop:ERROR",
]

# This list is from DISABLED_CHECKS in
# com/google/errorprone/scanner/BuiltInCheckerSuppliers.java
EP_DISABLED_CHECKS = [
    "-Xep:AutoFactoryAtInject:ERROR",
    "-Xep:AssertFalse:ERROR",
    "-Xep:AssistedInjectAndInjectOnConstructors:ERROR",
    "-Xep:AssistedInjectAndInjectOnSameConstructor:ERROR",
    "-Xep:BigDecimalLiteralDouble:ERROR",
    "-Xep:BindingToUnqualifiedCommonType:ERROR",
    "-Xep:ClassName:ERROR",
    "-Xep:ComparisonContractViolated:ERROR",
    "-Xep:ConstantField:ERROR",
    "-Xep:ConstructorInvokesOverridable:ERROR",
    # False positives, disabled
    # "-Xep:ConstructorLeaksThis:ERROR",
    "-Xep:DepAnn:ERROR",
    "-Xep:DivZero:ERROR",
    "-Xep:EmptyIfStatement:ERROR",
    "-Xep:EmptySetMultibindingContributions:ERROR",
    "-Xep:EmptyTopLevelDeclaration:ERROR",
    "-Xep:ExpectedExceptionChecker:ERROR",
    "-Xep:HardCodedSdCardPath:ERROR",
    "-Xep:InjectedConstructorAnnotations:ERROR",
    "-Xep:InsecureCipherMode:ERROR",
    "-Xep:InvalidTargetingOnScopingAnnotation:ERROR",
    "-Xep:IterablePathParameter:ERROR",
    "-Xep:JMockTestWithoutRunWithOrRuleAnnotation:ERROR",
    "-Xep:JavaxInjectOnFinalField:ERROR",
    "-Xep:LockMethodChecker:ERROR",
    "-Xep:LongLiteralLowerCaseSuffix:ERROR",
    "-Xep:MethodCanBeStatic:ERROR",
    "-Xep:MissingDefault:ERROR",
    "-Xep:MixedArrayDimensions:ERROR",
    "-Xep:MoreThanOneQualifier:ERROR",
    "-Xep:MultiVariableDeclaration:ERROR",
    "-Xep:MultipleTopLevelClasses:ERROR",
    "-Xep:NoAllocationChecker:ERROR",
    "-Xep:NonCanonicalStaticMemberImport:ERROR",
    "-Xep:NumericEquality:ERROR",
    "-Xep:PackageLocation:ERROR",
    "-Xep:PrimitiveArrayPassedToVarargsMethod:ERROR",
    "-Xep:PrivateConstructorForUtilityClass:ERROR",
    "-Xep:PrivateConstructorForNoninstantiableModule:ERROR",
    "-Xep:ProtoStringFieldReferenceEquality:ERROR",
    "-Xep:QualifierOrScopeOnInjectMethod:ERROR",
    "-Xep:QualifierWithTypeUse:ERROR",
    "-Xep:RedundantThrows:ERROR",
    "-Xep:RemoveUnusedImports:ERROR",
    "-Xep:ScopeAnnotationOnInterfaceOrAbstractClass:ERROR",
    "-Xep:ScopeOrQualifierAnnotationRetention:ERROR",
    "-Xep:StaticQualifiedUsingExpression:ERROR",
    "-Xep:StaticOrDefaultInterfaceMethod:ERROR",
    "-Xep:StringEquality:ERROR",
    "-Xep:TestExceptionChecker:ERROR",
    # TODO: stylistic changes in code
    # "-Xep:ThrowsUncheckedException:ERROR",
    # "-Xep:UngroupedOverloads:ERROR",
    "-Xep:UnlockMethodChecker:ERROR",
    "-Xep:UnnecessaryDefaultInEnumSwitch:ERROR",
    "-Xep:UnnecessaryStaticImport:ERROR",
    "-Xep:UseBinds:ERROR",
    "-Xep:VarChecker:ERROR",
    "-Xep:WildcardImport:ERROR",
    "-Xep:WrongParameterPackage:ERROR",
]

EP_OPTS = EP_ENABLED_WARNINGS + EP_DISABLED_CHECKS

JAVACOPTS = JAVA_VERSION_OPTS + XLINT_OPTS + EP_OPTS