Skip to content

Commit

Permalink
Upgrade Error Prone to 2.4.0.
Browse files Browse the repository at this point in the history
This is both the version targeted by NullAway, as well as the
one used to check NullAway's code for issues.

Due to `ErrorProneCompiler` being deleted upstream and replaced with
`ErrorProneJavaCompiler` (which has a different interface), this PR
also removes `compile-bench`, which we don't believe is under active
use.
  • Loading branch information
lazaroclapp committed Jun 23, 2020
1 parent 58f04c7 commit 5b0013e
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 239 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Expand Up @@ -48,13 +48,16 @@ subprojects { project ->
project.tasks.withType(JavaCompile) {
dependsOn(installGitHooks)
options.compilerArgs += [
"-Xlint:unchecked",
"-Xlint:deprecation",
"-Xlint:rawtypes",
"-Xlint:unchecked",
"-Werror"
]
options.errorprone {
// disable warnings in generated code; AutoValue code fails UnnecessaryParentheses check
disableWarningsInGeneratedCode = true
// Triggers for generated Android code (R.java)
check("MutablePublicArray", CheckSeverity.OFF)
// this check is too noisy
check("StringSplitter", CheckSeverity.OFF)
check("WildcardImport", CheckSeverity.ERROR)
Expand Down
12 changes: 0 additions & 12 deletions compile-bench/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions compile-bench/build.gradle

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions gradle/dependencies.gradle
Expand Up @@ -17,8 +17,8 @@
def versions = [
asm : "7.1",
checkerFramework : "3.0.0",
errorProne : "2.3.3", // The version of error prone running on this project
errorProneApi : "2.3.1", // The version of error prone built against and shipped
errorProne : "2.4.0", // The version of error prone running on this project
errorProneApi : "2.4.0", // The version of error prone built against and shipped
support : "27.1.1",
wala : "1.5.4",
commonscli : "1.4",
Expand Down
Expand Up @@ -193,7 +193,7 @@ private static void annotateBytecode(
* @param nonnullParams Map from methods to their nonnull params.
* @param nullableReturns List of methods that return nullable.
* @param debug flag to output debug logs.
* @throws IOException
* @throws IOException if an error happens when reading or writing to class streams.
*/
public static void annotateBytecodeInClass(
InputStream is,
Expand Down Expand Up @@ -262,8 +262,9 @@ private static void copyAndAnnotateJarEntry(
* @param nonnullParams Map from methods to their nonnull params.
* @param nullableReturns List of methods that return nullable.
* @param debug flag to output debug logs.
* @throws IOException
* @throws IOException if an error happens when reading or writing to jar or class streams.
*/
@SuppressWarnings("JdkObsolete")
public static void annotateBytecodeInJar(
JarFile inputJar,
JarOutputStream jarOS,
Expand Down Expand Up @@ -302,8 +303,9 @@ public static void annotateBytecodeInJar(
* @param nonnullParams Map from methods to their nonnull params.
* @param nullableReturns List of methods that return nullable.
* @param debug flag to output debug logs.
* @throws IOException
* @throws IOException if an error happens when reading or writing to AAR/JAR/class streams.
*/
@SuppressWarnings("JdkObsolete")
public static void annotateBytecodeInAar(
ZipFile inputZip,
ZipOutputStream zipOS,
Expand Down
Expand Up @@ -99,7 +99,7 @@ private static void LOG(boolean cond, String tag, String msg) {
/**
* This is the core analysis that identifies definitely-dereferenced parameters.
*
* @return Set<Integer> The ordinal indices of formal parameters that are definitely-dereferenced.
* @return The ordinal indices of formal parameters that are definitely-dereferenced.
*/
Set<Integer> analyze() {
// Get ExceptionPrunedCFG
Expand Down
Expand Up @@ -48,8 +48,9 @@ public class AnnotationChecker {
* that are expected to be present.
* @return True when the actual annotations that are expected to be present are present iff the
* 'Expect*' annotations are present.
* @throws IOException
* @throws IOException if an error happens when reading the AAR file.
*/
@SuppressWarnings("JdkObsolete")
public static boolean checkMethodAnnotationsInAar(
String aarFile, Map<String, String> expectedToActualAnnotations) throws IOException {
Preconditions.checkArgument(aarFile.endsWith(".aar"), "invalid aar file: " + aarFile);
Expand Down Expand Up @@ -83,8 +84,9 @@ public static boolean checkMethodAnnotationsInAar(
* that are expected to be present.
* @return True when the actual annotations that are expected to be present are present iff the
* 'Expect*' annotations are present.
* @throws IOException
* @throws IOException if an error happens when reading the jar file.
*/
@SuppressWarnings("JdkObsolete")
public static boolean checkMethodAnnotationsInJar(
String jarFile, Map<String, String> expectedToActualAnnotations) throws IOException {
Preconditions.checkArgument(jarFile.endsWith(".jar"), "invalid jar file: " + jarFile);
Expand Down
Expand Up @@ -19,11 +19,11 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.BaseErrorProneCompiler;
import com.google.errorprone.BaseErrorProneJavaCompiler;
import com.google.errorprone.DiagnosticTestHelper;
import com.google.errorprone.ErrorProneInMemoryFileManager;
import com.google.errorprone.bugpatterns.BugChecker;
import com.google.errorprone.scanner.ScannerSupplier;
import com.sun.tools.javac.main.Main;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;

Expand All @@ -54,8 +55,9 @@ public class CompilerUtil {

private final ErrorProneInMemoryFileManager fileManager;
private final List<JavaFileObject> sources = new ArrayList<>();
private final BaseErrorProneCompiler compiler;
private final BaseErrorProneJavaCompiler compiler;
private final ByteArrayOutputStream outputStream;
private final DiagnosticTestHelper diagnosticHelper;
private List<String> args = ImmutableList.of();

public CompilerUtil(Class<?> klass) {
Expand All @@ -66,15 +68,11 @@ public CompilerUtil(Class<?> klass) {
throw new RuntimeException("unexpected IOException", e);
}
outputStream = new ByteArrayOutputStream();
diagnosticHelper = new DiagnosticTestHelper();
this.compiler =
BaseErrorProneCompiler.builder()
.redirectOutputTo(
new PrintWriter(
new BufferedWriter(new OutputStreamWriter(outputStream, UTF_8)), true))
.report(
ScannerSupplier.fromBugCheckerClasses(
Collections.<Class<? extends BugChecker>>emptySet()))
.build();
new BaseErrorProneJavaCompiler(
ScannerSupplier.fromBugCheckerClasses(
Collections.<Class<? extends BugChecker>>emptySet()));
}
/**
* Adds a source file to the test compilation, from an existing resource file.
Expand All @@ -100,8 +98,18 @@ public CompilerUtil setArgs(List<String> args) {
return this;
}

private Main.Result compile(Iterable<JavaFileObject> sources, String[] args) {
return compiler.run(args, fileManager, ImmutableList.copyOf(sources), null);
private boolean compile(Iterable<JavaFileObject> sources, Iterable<String> args) {
PrintWriter writer =
new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream, UTF_8)), true);
JavaCompiler.CompilationTask task =
compiler.getTask(
writer,
fileManager,
diagnosticHelper.collector,
args,
null,
ImmutableList.copyOf(sources));
return task.call();
}

public String getOutput() {
Expand Down Expand Up @@ -130,9 +138,9 @@ private static List<String> disableImplicitProcessing(List<String> args) {
return ImmutableList.<String>builder().addAll(args).add("-proc:none").build();
}

public Main.Result run() {
public boolean run() {
Preconditions.checkState(!sources.isEmpty(), "No source files to compile");
List<String> allArgs = buildArguments(args);
return compile(sources, allArgs.toArray(new String[allArgs.size()]));
return compile(sources, allArgs);
}
}
Expand Up @@ -38,8 +38,9 @@ public class EntriesComparator {
* @param jarFile1 Path to the first jar file.
* @param jarFile2 Path to the second jar file.
* @return True iff the entries present in the two jar files are the same.
* @throws IOException
* @throws IOException if an error happens when reading jar files.
*/
@SuppressWarnings("JdkObsolete")
public static boolean compareEntriesInJars(String jarFile1, String jarFile2) throws IOException {
Preconditions.checkArgument(jarFile1.endsWith(".jar"), "invalid jar file: " + jarFile1);
Preconditions.checkArgument(jarFile2.endsWith(".jar"), "invalid jar file: " + jarFile2);
Expand All @@ -64,8 +65,9 @@ public static boolean compareEntriesInJars(String jarFile1, String jarFile2) thr
* @param aarFile2 Path to the second aar file.
* @return True iff the entries present in the two aar files are the same and entries in
* "classes.jar" in the two aar files are the same.
* @throws IOException
* @throws IOException if an error happens when reading aar files.
*/
@SuppressWarnings("JdkObsolete")
public static boolean compareEntriesInAars(String aarFile1, String aarFile2) throws IOException {
Preconditions.checkArgument(aarFile1.endsWith(".aar"), "invalid aar file: " + aarFile1);
Preconditions.checkArgument(aarFile2.endsWith(".aar"), "invalid aar file: " + aarFile2);
Expand Down Expand Up @@ -132,8 +134,8 @@ private static String readManifestFromJar(String jarfile) throws IOException {
* @param jarFile1 Path to the first jar file.
* @param jarFile2 Path to the second jar file.
* @return True iff the MANIFEST.MF files in the two jar files exist and are the same.
* @throws IOException
* @throws IllegalArgumentException
* @throws IOException if an error happens when reading jar files.
* @throws IllegalArgumentException if either jar does not contain a manifest.
*/
public static boolean compareManifestContents(String jarFile1, String jarFile2)
throws IOException {
Expand Down

0 comments on commit 5b0013e

Please sign in to comment.