Skip to content

[fixes #4051] Eclipse isClass must not treat non-type nodes as classes - #4054

Open
kamilkrzywanski wants to merge 1 commit into
projectlombok:masterfrom
kamilkrzywanski:issue-4051-eclipse-isclass-completion
Open

[fixes #4051] Eclipse isClass must not treat non-type nodes as classes#4054
kamilkrzywanski wants to merge 1 commit into
projectlombok:masterfrom
kamilkrzywanski:issue-4051-eclipse-isclass-completion

Conversation

@kamilkrzywanski

@kamilkrzywanski kamilkrzywanski commented Jul 11, 2026

Copy link
Copy Markdown

Summary

Fixes #4051: Eclipse/VSCode autocompletion crashed with ClassCastException: CompletionOnFieldType cannot be cast to TypeDeclaration in HandleValue (and potentially other type-level handlers).

Root cause: EclipseHandlerUtil.isTypeAndDoesNotHaveFlags (used by isClass(), isClassOrEnum(), …) returned true when the node was not a TypeDeclaration. Non-type nodes (including JDT's CompletionOnFieldType, which extends FieldDeclaration) got modifiers = 0, so (0 & flags) == 0 was true. Handlers then unguardedly cast to TypeDeclaration.

Fix: Match javac's JavacHandlerUtil.isClassAndDoesNotHaveFlags — return false immediately when the node is not a TypeDeclaration.

This is a single-point root-cause fix that protects all handlers relying on isClass / related helpers, not a HandleValue-only band-aid.

Reproducers / tests

  1. Unit test TestEclipseIsClass — fails on the old isClass(fieldNode) == true behavior; passes after the fix. Wired into TestEclipse (CI) and RunCoreTests.
  2. Transform tests for the reported scenario:
    • @Builder + @Jacksonized on an inner class of a sealed interface
    • same with @Value (the stacktrace path through HandleValue)

Compile-path (javac / mvn compile) already succeeded, as the issue stated; the bug is in the JDT completion AST path.

Test plan

  • TestEclipseIsClass fails before fix, passes after
  • ant test.javacCurrent — delombok transform tests for the new sealed-interface cases
  • ant test.eclipse-202503 — ECJ transform tests for the same cases
  • Full local ant test (javacCurrent + eclipse-202503)
  • Full CI on this PR

Note: pre-existing ValUndenotable ECJ failure on master

Local full ant test reports one ECJ failure that is not related to this PR:

[FAIL] ecj-ValUndenotable.java
Missing / empty expected file: ValUndenotable.java
  • test/transform/resource/before/ValUndenotable.java and after-delombok/ValUndenotable.java exist on master
  • after-ecj/ValUndenotable.java is missing on master as well (introduced with the JDK26/var work, without an ECJ golden file)

A/B check: temporarily reverted this PR's isTypeAndDoesNotHaveFlags change back to the master implementation and re-ran the ECJ suite:

Without this fix With this fix
TestEclipseIsClass (field node) FAIL (expected) PASS
ecj-ValUndenotable FAIL — missing after-ecj file FAIL — same missing file, same actual output

So ValUndenotable fails identically with or without this change; it is a pre-existing missing golden file, not a regression from #4051.

…des as classes

EclipseHandlerUtil.isTypeAndDoesNotHaveFlags returned true for non-
TypeDeclaration nodes (modifiers defaulted to 0). During JDT completion,
handlers such as HandleValue then cast CompletionOnFieldType to
TypeDeclaration and crashed with ClassCastException.

Align with javac's isClassAndDoesNotHaveFlags: return false when the node
is not a TypeDeclaration. Add a unit regression test and transform tests
for @Jacksonized/@builder on sealed-interface inner classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant