Skip to content

Fix Class.getSuperClass() infinite loop when called on java.lang.Object#39

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-getsuperclass-object-return
Draft

Fix Class.getSuperClass() infinite loop when called on java.lang.Object#39
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-getsuperclass-object-return

Conversation

Copy link

Copilot AI commented Mar 18, 2026

addDefaultSuperClass() unconditionally assigned java.lang.Object as the default superclass for any class without an explicit extends clause — including java.lang.Object itself — causing getSuperClass() to return Object for Object, producing an infinite loop when traversing the hierarchy transitively.

Change

  • JavaModelCompletion.addDefaultSuperClass(): Guard the default superclass assignment with a check against isJavaLangObject(), so java.lang.Object is never given a synthetic self-referential superclass.
// Before
if (javaClass.getExtends() == null && javaClass.getDefaultExtends() == null) {

// After
if (javaClass.getExtends() == null && javaClass.getDefaultExtends() == null
        && !javaClass.isJavaLangObject(javaClass)) {

java.lang.Object.getSuperClass() now returns null, correctly terminating transitive superclass traversal.

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix Class.getSuperClass() not to return Object for Object</issue_title>
<issue_description>getSuperclass() returns Object if a Class does not declare any concrete extension. This is also done for the class Object.

This may result in an endless loop when transitively traversing getSuperclass()
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…te loop

Co-authored-by: cwende <1968463+cwende@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Class.getSuperClass() not to return Object for Object Fix Class.getSuperClass() infinite loop when called on java.lang.Object Mar 18, 2026
Copilot AI requested a review from cwende March 18, 2026 08:21
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.

Fix Class.getSuperClass() not to return Object for Object

2 participants