Skip to content

Commit

Permalink
Ignore disabled checks passed to -XepPatchChecks
Browse files Browse the repository at this point in the history
Rather than throwing an `NoSuchElementException`.

Fixes google#3908.
  • Loading branch information
oxkitsune committed Jul 31, 2023
1 parent 29b0e54 commit 4d502e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,12 @@ static ErrorProneAnalyzer createAnalyzer(
.customRefactorer()
.or(
() -> {
ScannerSupplier toUse =
ErrorPronePlugins.loadPlugins(scannerSupplier, context)
.applyOverrides(epOptions);
ScannerSupplier toUse = ErrorPronePlugins.loadPlugins(scannerSupplier, context);
ImmutableSet<String> 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();

Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/com/google/errorprone/scanner/ScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {}

Expand Down

0 comments on commit 4d502e0

Please sign in to comment.