diff --git a/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java b/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java index eff5d443bc91..51cf7c94f95b 100644 --- a/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java +++ b/check_api/src/main/java/com/google/errorprone/BaseErrorProneJavaCompiler.java @@ -224,14 +224,12 @@ static ErrorProneAnalyzer createAnalyzer( .customRefactorer() .or( () -> { - ScannerSupplier toUse = - ErrorPronePlugins.loadPlugins(scannerSupplier, context) - .applyOverrides(epOptions); + ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context); ImmutableSet namedCheckers = epOptions.patchingOptions().namedCheckers(); if (!namedCheckers.isEmpty()) { toUse = toUse.filter(bci -> namedCheckers.contains(bci.canonicalName())); } - return ErrorProneScannerTransformer.create(toUse.get()); + return ErrorProneScannerTransformer.create(toUse.applyOverrides(epOptions).get()); }) .get(); diff --git a/core/src/test/java/com/google/errorprone/scanner/ScannerTest.java b/core/src/test/java/com/google/errorprone/scanner/ScannerTest.java index 39648b552df1..0a1a1899c8f7 100644 --- a/core/src/test/java/com/google/errorprone/scanner/ScannerTest.java +++ b/core/src/test/java/com/google/errorprone/scanner/ScannerTest.java @@ -95,6 +95,22 @@ public void suppressionAnnotationIgnoredWithOptions() { .doTest(); } + @Test + public void dontRunPatchForDisabledChecks() { + compilationHelper + .addSourceLines( + "Test.java", + "import com.google.errorprone.scanner.ScannerTest.Foo;", + "class Test {", + " Foo foo;", + "}") + .setArgs( + "-XepPatchLocation:IN_PLACE", + "-XepPatchChecks:ShouldNotUseFoo", + "-Xep:ShouldNotUseFoo:OFF") + .doTest(); + } + @OkToUseFoo // Foo can use itself. But this shouldn't suppress errors on *usages* of Foo. public static final class Foo {}