google / google/error-prone

2.40.0: Exception thrown when a check is disabled through an alternate name and `-XepPatchCheck:` is set

Open
#5,170 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

This is an issue similar to https://github.com/google/error-prone/issues/3908, which was fixed by https://github.com/google/error-prone/pull/4028, but specific to disabling a check through an alternate name.

I've built a reproducing test in https://github.com/google/error-prone/pull/5169, along with a description of the issue, which I'll copy over below.
=====
The aforementioned bug flagged that Error-prone was throwing an exception when patching checks that are disabled.

This was later fixed by https://github.com/google/error-prone/pull/4028.

However, this still fails when the check is disabled through an alternate name. Disabling it works fine in isolation, but it throws an exception when called with `-XepPatchChecks:`. It works fine if you use the main check name instead.

Below is an example such exception (reproduced with the `[InsecureCryptoUsage](https://github.com/google/error-prone/blob/4384ed81ed0b639307292bf5b12f820e8cfdd419/core/src/main/java/com/google/errorprone/bugpatterns/InsecureCipherMode.java)` check)
```
error: An unhandled exception was thrown by the Error Prone static analysis plugin.
KeyFactory.getInstance(Algorithm.RSA.toString());
^
Please report this at https://github.com/google/error-prone/issues/new and include the following:

error-prone version: 2.40.0
BugPattern: InsecureCryptoUsage
Stack Trace:
java.util.NoSuchElementException: No value present
at java.base/java.util.Optional.get(Optional.java:143)
at com.google.errorprone.matchers.Description.severity(Description.java:78)
at com.google.errorprone.ErrorProneAnalyzer.lambda$finished$3(ErrorProneAnalyzer.java:213)
at com.google.errorprone.VisitorState.reportMatch(VisitorState.java:302)
at com.google.errorprone.scanner.Scanner.reportMatch(Scanner.java:126)
at com.google.errorprone.scanner.ErrorProneScanner.processMatchers(ErrorProneScanner.java:508)
at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:824)
at com.google.errorprone.scanner.ErrorProneScanner.visitMethodInvocation(ErrorProneScanner.java:170)
at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCMethodInvocation.accept(JCTree.java:1813)

```
Side-note: The `InsecureCryptoUsage` check is a bit of an oddball in that its class name (`InsecureCipherMode`) [is the _alternate_ check name](https://github.com/google/error-prone/blob/4384ed81ed0b639307292bf5b12f820e8cfdd419/core/src/main/java/com/google/errorprone/bugpatterns/InsecureCipherMode.java#L37), not the main one, which makes it more intuitive to disable with the alternate name.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.