Skip to content

ClassGraph returns superclass constructors when asked for subclass constructors even if the subclass has a non-public constructor with the same signature as a super's constructor #920

@chubert-ch

Description

@chubert-ch

Already got a fix, just making this issue to have an issue number:

    @Test
    void test() {
        MethodInfoList constructors = new ClassGraph()
                .enableAnnotationInfo()
                .enableSystemJarsAndModules()
                .enableClassInfo()
                .enableMethodInfo()
                .scan()
                .getClassInfo("java.io.ObjectOutputStream")
                .getConstructorInfo();
        for (MethodInfo constructor : constructors) {
            if (constructor.getParameterInfo().length == 0) {
                // The no args constructor of ObjectOutputStream is protected
                assertEquals(Modifier.PROTECTED, constructor.getModifiers(), "The no-args constructor of ObjectOutputStream should read as `protected`");
            }
        }
    }

Basically, the constructor info returned is for the superclass constructor, but given constructors aren't inherited this seems more misleading than useful.

Also worth noting that the javadoc for getMethodInfo(final String methodName) says:

Returns information on the method(s) or constructor(s) of the given name declared by this class, but not by its interfaces or superclasses.

but currently it will in fact return a public superclass constructor if the subclass one is lower visibility and .ignoreMethodVisibility() isn't set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions