You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The -XepDisableWarningsInGeneratedCode flag suppresses warnings inside classes annotated with @Generated. However, this logic has no effect on CompilationUnitTreeMatchers, as a CompilationUnitTreeencompasses one or more classes.
Despite the @Generated annotation, two warnings are emitted:
Dummy.java:6: warning: [FieldCanBeFinal] This field is only assigned during initialization; consider making it final
private String prop;
^
(see https://errorprone.info/bugpattern/FieldCanBeFinal)
Did you mean 'private final String prop;'?
Dummy.java:2: warning: [RemoveUnusedImports] Unused imports
import java.util.Map;
^
(see https://errorprone.info/bugpattern/RemoveUnusedImports)
Did you mean to remove this line?
2 warnings
One possible solution would be to descend into CompilationUnitTrees to look for @Generated type declarations, and skip analysis if any are found. I wonder what the Error Prone team thinks of this approach. Maybe I'm overlooking a much more elegant and/or efficient solution.
NB: annotating a whole package as @Generated may be a workaround for this issue (didn't check), but such a workaround would in any case not be suitable for annotation processors which generate code in the same package as their "source type", like Google Auto Value or Immutables.
The text was updated successfully, but these errors were encountered:
…l classes when visiting CompilationUnitTrees.
This stops CompilationUnitTreeMatchers from firing on generated code when -XepDisableWarningsInGeneratedCode is passed.
Fixes#1165
RELNOTES: Suppress checks thoroughly when -XepDisableWarningsInGeneratedCode is passed.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229526286
…l classes when visiting CompilationUnitTrees.
This stops CompilationUnitTreeMatchers from firing on generated code when -XepDisableWarningsInGeneratedCode is passed.
Fixes#1165
RELNOTES: Suppress checks thoroughly when -XepDisableWarningsInGeneratedCode is passed.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=229526286
The
-XepDisableWarningsInGeneratedCode
flag suppresses warnings inside classes annotated with@Generated
. However, this logic has no effect onCompilationUnitTreeMatcher
s, as aCompilationUnitTree
encompasses one or more classes.For example, consider the following class:
Compile this code as follows:
javac \ -XDcompilePolicy=simple \ -processorpath error_prone_core-2.3.2-with-dependencies.jar \ '-Xplugin:ErrorProne -XepDisableAllChecks -XepDisableWarningsInGeneratedCode -Xep:FieldCanBeFinal:WARN -Xep:RemoveUnusedImports:WARN' \ Dummy.java
Despite the
@Generated
annotation, two warnings are emitted:One possible solution would be to descend into
CompilationUnitTree
s to look for@Generated
type declarations, and skip analysis if any are found. I wonder what the Error Prone team thinks of this approach. Maybe I'm overlooking a much more elegant and/or efficient solution.NB: annotating a whole package as
@Generated
may be a workaround for this issue (didn't check), but such a workaround would in any case not be suitable for annotation processors which generate code in the same package as their "source type", like Google Auto Value or Immutables.The text was updated successfully, but these errors were encountered: