Skip to content

Fix JDK 11 anonymous class bug and unify anonymous class handling - #1909

Merged
wmdietl merged 5 commits into
eisop:masterfrom
aosen-xiong:fix-jdk11-anonymous-class-detection
Aug 4, 2026
Merged

wmdietl merged 5 commits into
eisop:masterfrom
aosen-xiong:fix-jdk11-anonymous-class-detection

Conversation

@aosen-xiong

@aosen-xiong aosen-xiong commented Aug 1, 2026 •

Copy link
Copy Markdown
Collaborator

Found in #1013.

This PR adds a Nullness Checker test that exposes a JDK 11-specific anonymous-class detection bug.

For:

new @Nullable Object() {};

JDK 11 incorrectly reports two additional declaration.inconsistent.with.extends.clause
errors:

  • @Nullable cannot extend @NonNull
  • @UnknownInitialization cannot extend @Initialized

The problem is that TypesUtils.isAnonymous(TreeUtils.typeOf(classTree)) does not recognize
this annotated anonymous class on JDK 11. Newer JDKs do not produce these diagnostics.

This test-only commit is expected to fail the JDK 11 CI job, confirming the regression
before adding the framework fix.

Copilot AI review requested due to automatic review settings August 1, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a Nullness Checker regression test that targets a JDK 11-specific issue where an annotated anonymous class (new @Nullable Object() {}) is not recognized as anonymous, leading to extra (unexpected) diagnostics.

Changes:

  • Add a new Nullness test case covering type-use annotation on an anonymous class creation.
  • Expect only the intended nullness.on.new.object error so that JDK 11’s extra diagnostics cause the test to fail (until the framework fix is added).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread checker/tests/nullness/AnonymousClassTypeAnnotation.java

@wmdietl wmdietl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I went through this with Antigravity and cleaned up all anonymous class code.

@wmdietl wmdietl changed the title Add test for JDK 11 annotated anonymous class bug Fix JDK 11 anonymous class bug and unify anonymous class handling Aug 4, 2026
@wmdietl
wmdietl enabled auto-merge (squash) August 4, 2026 16:05
@wmdietl
wmdietl merged commit 5e7c2f5 into eisop:master Aug 4, 2026
42 checks passed
@aosen-xiong
aosen-xiong deleted the fix-jdk11-anonymous-class-detection branch August 4, 2026 16:53
aosen-xiong added a commit to aosen-xiong/checker-framework that referenced this pull request Aug 4, 2026
Replace TypesUtils.isAnonymous(TreeUtils.typeOf(...)) with
TreeUtils.isAnonymousClass(ClassTree) in MutabilityNoInitVisitor and
MutabilityValidator, following the API unification in eisop#1909
which fixes a JDK 11 anonymous class detection bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants