Skip to content

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

Description

@pony5551

我的代码修改如下
@native_method
def get_superclass(self, uc, env, clazz_idx):
"""
If clazz represents any class other than the class Object, then this function returns the object that represents the superclass of the class specified by clazz.

    If clazz specifies the class Object, or clazz represents an interface, this function returns NULL.
    """
    clazz = self.get_reference(clazz_idx)
    if not isinstance(clazz, jclass):
        raise ValueError('Expected a jclass.')
    
    # pony modfy start
    # Create class instance.
    class_obj = clazz.value
    pyclass = class_obj
    logger.debug("JNIEnv->GetSuperClass (%s) is called, index %d" % (pyclass.jvm_name, clazz_idx) )

    pyclazz_super = pyclass.jvm_super
    if (not pyclazz_super):
        raise RuntimeError("super class for %s is None!!! you should at least inherit Object!!!")
    #
    logger.debug("JNIEnv->GetSuperClass (%s) return (%s)"%(pyclass.jvm_name, pyclazz_super.jvm_name))
    # clazz_super_object = pyclazz_super.class_object
    return self.add_local_reference(jclass(pyclazz_super))

    # pony modfy end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions