-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingOverride: ignore generated method #4065
Comments
While looking into (the different but related) PicnicSupermarket/error-prone-support#716, I noticed that Lombok by default adds So an alternative works-out-of-the-box-for-all-checks solution could be the following: diff --git a/check_api/src/main/java/com/google/errorprone/SuppressionInfo.java b/check_api/src/main/java/com/google/errorprone/SuppressionInfo.java
index cb23c08dea..3b891b9cc5 100644
--- a/check_api/src/main/java/com/google/errorprone/SuppressionInfo.java
+++ b/check_api/src/main/java/com/google/errorprone/SuppressionInfo.java
@@ -85,7 +85,8 @@ public class SuppressionInfo {
return SuppressedState.SUPPRESSED;
}
if (suppressible.supportsSuppressWarnings()
- && !Collections.disjoint(suppressible.allNames(), suppressWarningsStrings)) {
+ && (suppressWarningsStrings.contains("all")
+ || !Collections.disjoint(suppressible.allNames(), suppressWarningsStrings))) {
return SuppressedState.SUPPRESSED;
}
if (suppressible.suppressedByAnyOf(customSuppressions, state)) {
diff --git a/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java b/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java
index 4693b70ef8..f6485134a0 100644
--- a/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java
+++ b/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java
@@ -99,6 +99,7 @@ import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
+import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.BiPredicate;
@@ -269,8 +270,12 @@ public abstract class BugChecker implements Suppressible, Serializable {
}
private boolean isSuppressed(SuppressWarnings suppression) {
- return suppression != null
- && !Collections.disjoint(Arrays.asList(suppression.value()), allNames());
+ if (suppression == null) {
+ return false;
+ }
+
+ List<String> suppressions = Arrays.asList(suppression.value());
+ return suppressions.contains("all") || !Collections.disjoint(suppressions, allNames());
}
/** If the Error Prone maintainers think that this is an acceptable solution then I wouldn't mind writing some unit tests for this and opening a PR. |
That SGTM overall. I think your proposal handles that, but it would be good to have test coverage to double-check it doesn't apply to 'undisableable' checks. I have some mixed feelings about
|
Agree. Both suggestions SGTM, though a separate check is perhaps a bit more versatile, as it would also cover suppressions targeted at other static analysis tools. W.r.t. opening a PR: I've added it to my TODO list for the coming days; need to first focus on a few other topics. (The modified methods and surrounding |
I think this would solve a lot of issues, as this is not the only check that is conflicting with Lombok. Thanks @Stephan202 and @cushon for the quick response 👌 |
Practical question for @cushon :) Context: if made But: complete testing of the modified methods, without changing method visibility, requires constructing suitable
I think option (2) will yield the most robust and maintainable code, and this is the approach also taken for |
Thanks for working on this @Stephan202! I'm happy to be pragmatic about either of the options you described. If writing the test with |
Checks that are suppressed using `@SuppressWarnings("CheckName")` are now also suppressed by `@SuppressWarnings("all")`, as emitted by libraries such as Lombok and Immutables. Checks that are unsuppressible, or can only be suppressed by a custom annotation are _not_ suppressed by `@SuppressWarnings("all")`. While there: improve the deprecated `BugChecker#isSuppressed(Tree)` and `BugChecker#isSuppressed(Symbol)` methods to respect `BugChecker#supportsSuppressWarnings()`. Resolves #4065. Fixes #4076 FUTURE_COPYBARA_INTEGRATE_REVIEW=#4076 from PicnicSupermarket:sschroevers/suppress-warnings-all 1b8f663 PiperOrigin-RevId: 565426144
MissingOverride generates warnings for methods that have
@Generated
annotation.In #1968 there was a fix done by skipping classes that have the annotation.
However, if just parts of the class are generated, as with Lombok, the class level
@Generated
annotation is missing.I would expect methods with
@Generated
to be ignored/skipped.Minimal Reproducible Example
A full reproducable example is available at https://github.com/pacbeckh/error-prone-missing-override-issue, run
mvn clean install
Logs
Setup
MacOS Ventura
.17.0.4
).2.21.1
.The text was updated successfully, but these errors were encountered: