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 authored and Stephan202 committed Sep 13, 2023
1 parent 35e51f3 commit 5865373
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 @@ -224,14 +224,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 5865373

Please sign in to comment.