Skip to content

fix: use jvm_super in GetSuperclass - #90

Open
r8e8cd8 wants to merge 1 commit into
AeonLucid:masterfrom
r8e8cd8:fix/get-superclass-jvm-super
Open

r8e8cd8 wants to merge 1 commit into
AeonLucid:masterfrom
r8e8cd8:fix/get-superclass-jvm-super

Conversation

@r8e8cd8

@r8e8cd8 r8e8cd8 commented Nov 16, 2026

Copy link
Copy Markdown

Fixes #83

Problem

GetSuperclass previously used Python __mro__[1] to determine the superclass.

For classes defined with JavaClassDef(..., jvm_super=Parent), __mro__[1] is still object, resulting in the wrong JNI superclass.

Python MRO reflects implementation-language inheritance, not the emulated Java hierarchy. This project models Java inheritance via jvm_super.

This caused RegisterNatives and other JNI calls to resolve methods against object instead of the actual Java superclass, leading to the failures described in #83.

Previously GetSuperclass(Dog) would return object (via __mro__[1]); with this change it correctly returns Animal. Classes with no jvm_super return NULL, matching JNI spec behavior.

Change

Read jvm_super instead of __mro__. If unset (or not a class), return NULL.

jvm_super is expected to reference a JavaClassDef-based class.

Per the JNI spec, GetSuperclass returns NULL for java.lang.Object and interfaces — it is not an error condition.

Test

tests/test_get_superclass.py

Happy to adjust if anything looks off!

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.

get_superclass 有一个错误,会导致register_natives 中获取的clazz_id不正确

1 participant