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 #3908.

Fixes #4028

FUTURE_COPYBARA_INTEGRATE_REVIEW=#4028 from PicnicSupermarket:gdejong/remove-disabled-checks 4d502e0
PiperOrigin-RevId: 563488388
  • Loading branch information
oxkitsune authored and Error Prone Team committed Sep 8, 2023
1 parent 5c5ec33 commit c900f13
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 c900f13

Please sign in to comment.