Skip to content

8392955: Op.ofElement crashes with qualified anonymous inner classes - #1205

Open
dbalek wants to merge 1 commit into
openjdk:code-reflectionfrom
dbalek:dbalek/8392955
Open

dbalek wants to merge 1 commit into
openjdk:code-reflectionfrom
dbalek:dbalek/8392955

Conversation

@dbalek

@dbalek dbalek commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Consider the following code snippet:

import jdk.incubator.code.Reflect;

class Test {
    @Reflect
    void test() {
        Inner value = new Inner() {};
    }

    class Inner {
    }
}

When accessing the test method’s code model from an annotation processor via Op.ofElement(...), the following error is thrown:

java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:5671)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5632)
at jdk.compiler/com.sun.tools.javac.comp.Attr.attribClass(Attr.java:5447)
...

Op.ofElement calls Attr.runWithAttributedMethod, which passes the original method body to DeferredAttr.attribSpeculative. The anonymous class is entered as Test$1. Attributing its superclass recursively attributes its owners, eventually attributing entire Test class. The same anonymous class AST is then entered again as Test$2, overwriting tree.sym. The original attribution resumes with c == Test$1, but tree.sym == Test$2, causing the assertion in Attr.attribClassBody to fail.

The proposed solution is to replace the single method attribution performed by Attr.runWithAttributedMethod with a call to attribClass(env.enclClass.sym), thereby attributing the entire enclosing class. This should prevent recursive re-entry and the resulting instability in anonymous class numbering. A similar approach is already used by JavacTrees.getElement(TreePath path).



Progress

  • Change must not contain extraneous whitespace

Issue

  • JDK-8392955: Op.ofElement crashes with qualified anonymous inner classes (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1205

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/1205.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper

bridgekeeper Bot commented Oct 7, 2026

Copy link
Copy Markdown

👋 Welcome back dbalek! A progress list of the required criteria for merging this PR into code-reflection 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 Oct 7, 2026 •

Copy link
Copy Markdown

@dbalek 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:

8392955: Op.ofElement crashes with qualified anonymous inner classes

Reviewed-by: psandoz

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

At the time when this comment was updated there had been no new commits pushed to the code-reflection branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@PaulSandoz) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk Bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Oct 7, 2026
@mlbridge

mlbridge Bot commented Oct 7, 2026

Copy link
Copy Markdown

Webrevs

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

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants