Description of the problem / feature request:
Multiple annotations inside com.google.errorprone:error_prone_annotations use the meta-annotation @IncompatibleModifiers(FINAL).
Here, FINAL references javax.lang.model.element.Modifier.FINAL. However, the android.jar file used to build Android projects does not include javax.lang.model.element.Modifier.
This results in the following error whenever code using @Var, @LazyInit, @ForOverride, etc. is compiled for Android with a -Werror flag (our default setup):
warning: unknown enum constant Modifier.FINAL
reason: class file for javax.lang.model.element.Modifier not found
error: warnings found and -Werror specified
1 error
1 warning
For an example, here is a simple repro as a standalone Android project using gradle (see below for instructions).
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
git clone https://github.com/lazaroclapp/ep_modifiers_android_repro.git
gradle build
Observe:
warning: unknown enum constant Modifier.FINAL
reason: class file for javax.lang.model.element.Modifier not found
error: warnings found and -Werror specified
1 error
1 warning
What version of Error Prone are you using?
Can repro on 2.5.1, 2.4, and 2.3.3
Have you found anything relevant by searching the web?
I posted on the mailing list and got prompt help from Liam figuring out the root cause of the issue. Thanks!
My recommended solution
The real problem here is @IncompatibleModifiers and its use of javax.lang.model.element.Modifier's enum values as annotation parameters.
Could com.google.errorprone:error_prone_annotations perhaps include a separate Modifier enum that doesn't depend on javax.lang.model.element.Modifier, and use that for the public API of the @IncompatibleModifiers meta-annotation and for annotating the relevant Error Prone annotations?
This will likely complicate IncompatibleModifiersChecker a bit, or require a mapping from the new custom Modifier enum to javax.lang.model.element.Modifier, but it will make the annotation fully compatible with Android builds.
FYI, if you agree that supporting Android with -Werror is important, and that the above is a reasonable solution, I'd be more than happy to give it a first try at a PR that replaces javax.lang.model.element.Modifier with e.g. com.google.errorprone.annotations.Modifier.
Description of the problem / feature request:
Multiple annotations inside
com.google.errorprone:error_prone_annotationsuse the meta-annotation@IncompatibleModifiers(FINAL).Here,
FINALreferencesjavax.lang.model.element.Modifier.FINAL. However, theandroid.jarfile used to build Android projects does not includejavax.lang.model.element.Modifier.This results in the following error whenever code using
@Var,@LazyInit,@ForOverride, etc. is compiled for Android with a-Werrorflag (our default setup):For an example, here is a simple repro as a standalone Android project using gradle (see below for instructions).
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Observe:
What version of Error Prone are you using?
Can repro on 2.5.1, 2.4, and 2.3.3
Have you found anything relevant by searching the web?
I posted on the mailing list and got prompt help from Liam figuring out the root cause of the issue. Thanks!
My recommended solution
The real problem here is
@IncompatibleModifiersand its use ofjavax.lang.model.element.Modifier's enum values as annotation parameters.Could
com.google.errorprone:error_prone_annotationsperhaps include a separateModifierenum that doesn't depend onjavax.lang.model.element.Modifier, and use that for the public API of the@IncompatibleModifiersmeta-annotation and for annotating the relevant Error Prone annotations?This will likely complicate
IncompatibleModifiersCheckera bit, or require a mapping from the new customModifierenum tojavax.lang.model.element.Modifier, but it will make the annotation fully compatible with Android builds.FYI, if you agree that supporting Android with
-Werroris important, and that the above is a reasonable solution, I'd be more than happy to give it a first try at a PR that replacesjavax.lang.model.element.Modifierwith e.g.com.google.errorprone.annotations.Modifier.