RFR: 8305250: Unnecessary "unknown enum constant" warning emitted by javac when dependency has optional annotations with enums
Jan Lahoda
jlahoda at openjdk.org
Thu Feb 19 15:06:38 UTC 2026
Consider snippet like:
@UnresolvableAnnotation
int f1;
@UnresolvableAnnotation(unresolvable = 0)
int f2;
@UnresolvableAnnotation(unresolvable=UnresolvableEnum.A)
int f3;
javac will currently handle the 3 unresolvable aspects completely differently:
- for `UnresolvableAnnotation`, there is no error, and no warning,
- for `unresolvable` (attribute), there's no error, and a lint warning bound to `-Xlint:classfile`,
- for `UnresolvableEnum` (either the enum type, or an enum constant), there's no error, and an unconditional warning.
Note that the attribute method may primarily be unresolvable, because the annotation type is unresolvable.
This appears to cause issues for projects that read classfiles with annotations, but don't have the corresponding annotation API on the classpath.
The proposal herein is twofold:
- the warning for the `UnresolvableEnum` will now be an `-Xlint:classfile` warning as well, so it will be suppressible. This is for consistency.
- if the annotation type of an annotation is not resolvable, suppress/ignore all warnings inside that annotation. This is to aid cases where the annotation API is intentionally not on the classpath, which is valid to some degree (to mimic runtime behavior).
Note that if the annotation type is resolvable, than the warnings for the nested elements will continue to be reported. Such cases either means a wrong version of the annotation/enum type was used, or a likely classpath misconfiguration, and hence the warning does not see unwarranted there.
-------------
Commit messages:
- Removing trailing whitespace.
- 8305250: Unnecessary "unknown enum constant" warning emitted by javac when dependency has optional annotations with enums
Changes: https://git.openjdk.org/jdk/pull/29818/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=29818&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8305250
Stats: 264 lines in 6 files changed: 242 ins; 3 del; 19 mod
Patch: https://git.openjdk.org/jdk/pull/29818.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/29818/head:pull/29818
PR: https://git.openjdk.org/jdk/pull/29818
More information about the compiler-dev
mailing list