[fixes #4051] Eclipse isClass must not treat non-type nodes as classes - #4054
Open
kamilkrzywanski wants to merge 1 commit into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4051: Eclipse/VSCode autocompletion crashed with
ClassCastException: CompletionOnFieldType cannot be cast to TypeDeclarationinHandleValue(and potentially other type-level handlers).Root cause:
EclipseHandlerUtil.isTypeAndDoesNotHaveFlags(used byisClass(),isClassOrEnum(), …) returnedtruewhen the node was not aTypeDeclaration. Non-type nodes (including JDT'sCompletionOnFieldType, which extendsFieldDeclaration) gotmodifiers = 0, so(0 & flags) == 0was true. Handlers then unguardedly cast toTypeDeclaration.Fix: Match javac's
JavacHandlerUtil.isClassAndDoesNotHaveFlags— returnfalseimmediately when the node is not aTypeDeclaration.This is a single-point root-cause fix that protects all handlers relying on
isClass/ related helpers, not aHandleValue-only band-aid.Reproducers / tests
TestEclipseIsClass— fails on the oldisClass(fieldNode) == truebehavior; passes after the fix. Wired intoTestEclipse(CI) andRunCoreTests.@Builder+@Jacksonizedon an inner class of a sealed interface@Value(the stacktrace path throughHandleValue)Compile-path (
javac/mvn compile) already succeeded, as the issue stated; the bug is in the JDT completion AST path.Test plan
TestEclipseIsClassfails before fix, passes afterant test.javacCurrent— delombok transform tests for the new sealed-interface casesant test.eclipse-202503— ECJ transform tests for the same casesant test(javacCurrent + eclipse-202503)Note: pre-existing
ValUndenotableECJ failure on masterLocal full
ant testreports one ECJ failure that is not related to this PR:test/transform/resource/before/ValUndenotable.javaandafter-delombok/ValUndenotable.javaexist onmasterafter-ecj/ValUndenotable.javais missing onmasteras well (introduced with the JDK26/varwork, without an ECJ golden file)A/B check: temporarily reverted this PR's
isTypeAndDoesNotHaveFlagschange back to the master implementation and re-ran the ECJ suite:TestEclipseIsClass(field node)ecj-ValUndenotableafter-ecjfileSo
ValUndenotablefails identically with or without this change; it is a pre-existing missing golden file, not a regression from #4051.