Apache Solr open-source search software
LUCENE-9497: Integerate Error Prone ( Static Analysis Tool ) during compilation (#1816)
Varun Thacker121b26238969
diff --git a/build.gradle b/build.gradleindex d20deeb9385..f01045bf65f 100644--- a/build.gradle+++ b/build.gradle@@ -24,6 +24,7 @@ plugins {id "org.owasp.dependencycheck" version "5.3.0"id 'de.thetaphi.forbiddenapis' version '3.0.1' apply falseid "de.undercouch.download" version "4.0.2" apply false+ id "net.ltgt.errorprone" version "1.2.1" apply false}apply from: file('gradle/defaults.gradle')@@ -127,6 +128,7 @@ apply from: file('gradle/ide/intellij-idea.gradle')apply from: file('gradle/ide/eclipse.gradle')// Validation tasks+apply from: file('gradle/validation/error-prone.gradle')apply from: file('gradle/validation/precommit.gradle')apply from: file('gradle/validation/forbidden-apis.gradle')apply from: file('gradle/validation/jar-checks.gradle')diff --git a/gradle/defaults-java.gradle b/gradle/defaults-java.gradleindex 3614ee811e9..9e1b67ca980 100644--- a/gradle/defaults-java.gradle+++ b/gradle/defaults-java.gradle@@ -52,8 +52,11 @@ allprojects {"-Xdoclint:-missing","-Xdoclint:-accessibility","-proc:none", // proc:none was added because of LOG4J2-1925 / JDK-8186647- "-Werror",]++ if (propertyOrDefault("javac.failOnWarnings", true).toBoolean()) {+ options.compilerArgs += "-Werror"+ }}}}diff --git a/gradle/hacks/findbugs.gradle b/gradle/hacks/findbugs.gradleindex 06a6c76f694..f228738936e 100644--- a/gradle/hacks/findbugs.gradle+++ b/gradle/hacks/findbugs.gradle@@ -16,13 +16,14 @@*/// See LUCENE-9411. This hack adds compile-time only dependencies-// on findbugs annotations. Otherwise javac generates odd warnings about missing+// on findbugs and error_prone annotations. Otherwise javac generates odd warnings about missing// type information.configure([project(":solr:core"),project(":solr:solrj"),project(":solr:contrib:prometheus-exporter"),- project(":solr:test-framework")]) {+ project(":solr:test-framework"),+ project(":solr:contrib:analytics")]) {plugins.withType(JavaPlugin) {dependencies {// Use versionless variants because these libraries are in versions.lock.diff --git a/gradle/validation/error-prone.gradle b/gradle/validation/error-prone.gradlenew file mode 100644index 00000000000..d91fbb423c8--- /dev/null+++ b/gradle/validation/error-prone.gradle@@ -0,0 +1,149 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++allprojects { prj ->+ plugins.withType(JavaPlugin) {+ prj.apply plugin: 'net.ltgt.errorprone'++ dependencies {+ errorprone("com.google.errorprone:error_prone_core")+ }++ tasks.withType(JavaCompile) { task ->+ options.errorprone.disableWarningsInGeneratedCode = true+ options.errorprone.errorproneArgs = [+ // test+ '-Xep:ExtendingJUnitAssert:OFF',+ '-Xep:UseCorrectAssertInTests:OFF',+ '-Xep:DefaultPackage:OFF',+ '-Xep:FloatingPointLiteralPrecision:OFF',+ '-Xep:CatchFail:OFF',+ '-Xep:TryFailThrowable:OFF',+ '-Xep:MathAbsoluteRandom:OFF',+ '-Xep:AssertionFailureIgnored:OFF',+ '-Xep:JUnit4TestNotRun:OFF',+ '-Xep:FallThrough:OFF',+ '-Xep:CatchAndPrintStackTrace:OFF',+ '-Xep:ToStringReturnsNull:OFF',+ '-Xep:ArrayAsKeyOfSetOrMap:OFF',+ '-Xep:StaticAssignmentInConstructor:OFF',+ '-Xep:SelfAssignment:OFF',+ '-Xep:InvalidPatternSyntax:OFF',+ '-Xep:MissingFail:OFF',+ '-Xep:LossyPrimitiveCompare:OFF',+ '-Xep:ComparableType:OFF',+ '-Xep:InfiniteRecursion:OFF',+ '-Xep:MisusedDayOfYear:OFF',+ '-Xep:FloatingPointAssertionWithinEpsilon:OFF',++ '-Xep:ThrowNull:OFF',+ '-Xep:StaticGuardedByInstance:OFF',+ '-Xep:ArrayHashCode:OFF',+ '-Xep:ArrayEquals:OFF',+ '-Xep:IdentityBinaryExpression:OFF',+ '-Xep:ComplexBooleanConstant:OFF',+ '-Xep:ComplexBooleanConstant:OFF',+ '-Xep:StreamResourceLeak:OFF',+ '-Xep:UnnecessaryLambda:OFF',+ '-Xep:ObjectToString:OFF',+ '-Xep:URLEqualsHashCode:OFF',+ '-Xep:DoubleBraceInitialization:OFF',+ '-Xep:ShortCircuitBoolean:OFF',+ '-Xep:InputStreamSlowMultibyteRead:OFF',+ '-Xep:NonCanonicalType:OFF',+ '-Xep:CollectionIncompatibleType:OFF',+ '-Xep:TypeParameterShadowing:OFF',+ '-Xep:ThreadJoinLoop:OFF',+ '-Xep:MutableConstantField:OFF',+ '-Xep:ReturnValueIgnored:OFF',+ '-Xep:CollectionIncompatibleType:OFF',+ '-Xep:SameNameButDifferent:OFF',+ '-Xep:InvalidParam:OFF',+ '-Xep:CompareToZero:OFF',+ '-Xep:DoubleCheckedLocking:OFF',+ '-Xep:BadShiftAmount:OFF',+ '-Xep:CollectionUndefinedEquality:OFF',+ '-Xep:UnescapedEntity:OFF',+ '-Xep:BoxedPrimitiveEquality:OFF',+ '-Xep:LogicalAssignment:OFF',+ '-Xep:DoubleCheckedLocking:OFF',+ '-Xep:AmbiguousMethodReference:OFF',+ '-Xep:FormatString:OFF',+ '-Xep:InstanceOfAndCastMatchWrongType:OFF',+ '-Xep:ModifyCollectionInEnhancedForLoop:OFF',+ '-Xep:JavaLangClash:OFF',+ '-Xep:TypeParameterUnusedInFormals:OFF',+ '-Xep:UnusedNestedClass:OFF',+ '-Xep:OverrideThrowableToString:OFF',+ '-Xep:FutureReturnValueIgnored:OFF',+ '-Xep:BadInstanceof:OFF',+ '-Xep:UnusedNestedClass:OFF',+ '-Xep:OverrideThrowableToString:OFF',+ '-Xep:EqualsIncompatibleType:OFF',+ '-Xep:ByteBufferBackingArray:OFF',+ '-Xep:ByteBufferBackingArray:OFF',+ '-Xep:UnusedMethod:OFF',+ '-Xep:ObjectsHashCodePrimitive:OFF',+ '-Xep:ObjectsHashCodePrimitive:OFF',+ '-Xep:UnnecessaryAnonymousClass:OFF',+ '-Xep:BoxedPrimitiveConstructor:OFF',+ '-Xep:ArgumentSelectionDefectChecker:OFF',+ '-Xep:StringSplitter:OFF',+ '-Xep:MixedMutabilityReturnType:OFF',+ '-Xep:EqualsUnsafeCast:OFF',+ '-Xep:OperatorPrecedence:OFF',+ '-Xep:HidingField:OFF',+ '-Xep:ThreadPriorityCheck:OFF',+ '-Xep:InlineFormatString:OFF',+ '-Xep:EqualsUnsafeCast:OFF',+ '-Xep:UnsynchronizedOverridesSynchronized:OFF',+ '-Xep:OperatorPrecedence:OFF',+ '-Xep:ArrayToString:OFF',+ '-Xep:ClassCanBeStatic:OFF',+ '-Xep:InvalidInlineTag:OFF',+ '-Xep:EmptyCatch:OFF',+ '-Xep:UnnecessaryParentheses:OFF',+ '-Xep:AlmostJavadoc:OFF',+ '-Xep:Finally:OFF',+ '-Xep:ImmutableEnumChecker:OFF',+ '-Xep:NonAtomicVolatileUpdate:OFF',+ '-Xep:MutablePublicArray:OFF',+ '-Xep:LockNotBeforeTry:OFF',+ '-Xep:WaitNotInLoop:OFF',+ '-Xep:UndefinedEquals:OFF',+ '-Xep:JdkObsolete:OFF',+ '-Xep:NarrowingCompoundAssignment:OFF',+ '-Xep:InconsistentCapitalization:OFF',+ '-Xep:IntLongMath:OFF',+ '-Xep:SynchronizeOnNonFinalField:OFF',+ '-Xep:ThreadLocalUsage:OFF',+ '-Xep:ProtectedMembersInFinalClass:OFF',+ '-Xep:BadImport:OFF',+ '-Xep:InconsistentHashCode:OFF',+ '-Xep:MissingOverride:OFF',+ '-Xep:EqualsGetClass:OFF',+ '-Xep:PublicConstructorForAbstractClass:OFF',+ '-Xep:EscapedEntity:OFF',+ '-Xep:ModifiedButNotUsed:OFF',+ '-Xep:ReferenceEquality:OFF',+ '-Xep:InvalidBlockTag:OFF',+ '-Xep:MissingSummary:OFF',+ '-Xep:UnusedVariable:OFF'+ ]+ }+ }+}diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 830ad1ba4c1..bdc9e460493 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -231,6 +231,11 @@ Documentation* LUCENE-9424: Add a performance warning to AttributeSource.captureState javadocs (Haoyu Zhai)+Other+---------------------++* LUCENE-9497: Integrate Error Prone, a static analysis tool during compilation (Dawid Weiss, Varun Thacker)+Other---------------------diff --git a/lucene/core/src/java/org/apache/lucene/analysis/CharArrayMap.java b/lucene/core/src/java/org/apache/lucene/analysis/CharArrayMap.javaindex cad339b380f..ac88886aac7 100644--- a/lucene/core/src/java/org/apache/lucene/analysis/CharArrayMap.java+++ b/lucene/core/src/java/org/apache/lucene/analysis/CharArrayMap.java@@ -523,6 +523,7 @@ public class CharArrayMap<V> extends AbstractMap<Object,V> {* @throws NullPointerException* if the given map is <code>null</code>.*/+ @SuppressWarnings("ReferenceEquality")public static <V> CharArrayMap<V> unmodifiableMap(CharArrayMap<V> map) {if (map == null)throw new NullPointerException("Given map is null");diff --git a/versions.lock b/versions.lockindex 6670238149f..a606bd8b4f3 100644--- a/versions.lock+++ b/versions.lock@@ -15,7 +15,7 @@ com.github.virtuald:curvesapi:1.06 (1 constraints: db04f530)com.github.zafarkhaja:java-semver:0.9.0 (1 constraints: 0b050636)com.google.code.findbugs:annotations:3.0.1 (1 constraints: 0605fb35)com.google.code.findbugs:jsr305:3.0.2 (2 constraints: cd195721)-com.google.errorprone:error_prone_annotations:2.1.3 (1 constraints: 180aebb4)+com.google.errorprone:error_prone_annotations:2.4.0 (2 constraints: 1f0fd486)com.google.guava:guava:25.1-jre (1 constraints: 4a06b047)com.google.j2objc:j2objc-annotations:1.1 (1 constraints: b609eba0)com.google.protobuf:protobuf-java:3.11.0 (1 constraints: 3705383b)diff --git a/versions.props b/versions.propsindex 8c25e307d82..39a4f175666 100644--- a/versions.props+++ b/versions.props@@ -8,6 +8,7 @@ com.fasterxml.jackson*:*=2.10.1com.github.ben-manes.caffeine:caffeine=2.8.4com.github.virtuald:curvesapi=1.06com.github.zafarkhaja:java-semver=0.9.0+com.google.errorprone:*=2.4.0com.google.guava:guava=25.1-jrecom.google.protobuf:protobuf-java=3.11.0com.google.re2j:re2j=1.2