Skip to content

ClassInfo#getMethodInfo picks wrong inherited method #772

@peter-schmitz

Description

@peter-schmitz

Hi,

I believe ClassInfo#getOverrideOrder() is incorrect for methods and should probably prefer methodInfos from direct super classes before any interface methods.
After a quick test, the current order does appear to be correct for fields / interface constants.

Tested with JDK 8 and JDK 17.

Example:

Class: java.io.DataOutputStream
Method "close":

ClassLoader.getSystemClassLoader().loadClass("java.io.DataOutputStream").getMethod("close")

-> Returns: public void java.io.FilterOutputStream.close() throws java.io.IOException

ClassGraph graph = new ClassGraph()
        .enableClassInfo()
        .enableMethodInfo()
        .acceptClasses("java.io.DataOutputStream")
        .enableSystemJarsAndModules();

try (ScanResult scan = graph.scan()) {
    ClassInfo classInfo = scan.getClassInfo("java.io.DataOutputStream");
    MethodInfoList closeMethods = classInfo.getMethodInfo("close");
    for (MethodInfo closeMethod : closeMethods) {
        System.out.println(closeMethod + " from " + closeMethod.getClassInfo().getName());
    }
    //For some reason, the classInfo.getMethodInfo() list contains the abstract close method as well?
}

prints

public abstract void close() throws java.io.IOException from java.io.Closeable

Expected output:
public void close() throws java.io.IOException from java.io.FilterOutputStream

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions