Skip to content

8305250: Unnecessary "unknown enum constant" warning emitted by javac when dependency has optional annotations with enums - #29818

Closed
lahodaj wants to merge 3 commits into
openjdk:masterfrom
lahodaj:JDK-8305250
Closed

lahodaj wants to merge 3 commits into
openjdk:masterfrom
lahodaj:JDK-8305250

Conversation

@lahodaj

@lahodaj lahodaj commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8305250: Unnecessary "unknown enum constant" warning emitted by javac when dependency has optional annotations with enums (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29818/head:pull/29818
$ git checkout pull/29818

Update a local copy of the PR:
$ git checkout pull/29818
$ git pull https://git.openjdk.org/jdk.git pull/29818/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29818

View PR using the GUI difftool:
$ git pr show -t 29818

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29818.diff

Using Webrev

Link to Webrev Comment

… when dependency has optional annotations with enums
@bridgekeeper

bridgekeeper Bot commented Feb 19, 2026

Copy link
Copy Markdown

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk

openjdk Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

@lahodaj This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8305250: Unnecessary "unknown enum constant" warning emitted by javac when dependency has optional annotations with enums

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 37 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk Bot added the compiler compiler-dev@openjdk.org label Feb 19, 2026
@openjdk

openjdk Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label Feb 19, 2026
@mlbridge

mlbridge Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

Webrevs

@cushon cushon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, for what it's worth.

bazelbuild/bazel#5985 is another example of these warnings causing problems, I think putting them behind -Xlint:classfile makes sense.

return new Attribute.Compound(annotationType, buf.toList());
} finally {
if (!annotationType.tsym.type.hasTag(TypeTag.ERROR)) {
//if the annotation type does not exists

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "should not exist" (not exists)

@vy

vy commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

@lahodaj, thanks so much for picking this up. Would you mind giving the community some extra time to evaluate the effects of this change before integrating it, please?

FWIW, I will link certain issues that I know of are affected by this change:

I'm pretty sure there are hundreds of more out there in the wild.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copyright year needs to be updated.

@vicente-romero-oracle vicente-romero-oracle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Feb 20, 2026
@vy

vy commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

@Vampire has reported that this helps with Log4j: apache/logging-log4j2#4034 (comment)

@lahodaj

lahodaj commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

/integrate

@openjdk

openjdk Bot commented Mar 12, 2026

Copy link
Copy Markdown

Going to push as commit 26bb357.
Since your change was applied there have been 351 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk Bot added the integrated Pull request has been integrated label Mar 12, 2026
@openjdk openjdk Bot closed this Mar 12, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Mar 12, 2026
@openjdk

openjdk Bot commented Mar 12, 2026

Copy link
Copy Markdown

@lahodaj Pushed as commit 26bb357.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler compiler-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants