Skip to content

ClassInfo.getClassDependencies doesn't look into method body. #413

@PYangDizzle

Description

@PYangDizzle

According to the ClassInfo wiki, ClassGraph is capable of inspecting the method implementation to find dependencies.

ClassInfo#getClassDependencies() returns a ClassInfoList for all the classes a given class depends upon, by looking for class references in superclasses, interfaces, methods, fields, annotations, local variables, intermediate values within a method's code, concrete type parameters, etc.

However, getClassDependencies doesn't do that.

I turned on verbose and noticed that temp.Source is recognized at one point.

2020-04-03T17:52:34.548-0500 ClassGraph ------------ Found class temp.RegressionTarget
2020-04-03T17:52:34.548-0500 ClassGraph -------------- Superclass: java.lang.Object
2020-04-03T17:52:34.548-0500 ClassGraph -------------- Method: ()
2020-04-03T17:52:34.549-0500 ClassGraph -------------- Method: public static void doSomething()
2020-04-03T17:52:34.549-0500 ClassGraph -------------- Referenced class names: java.lang.Object, temp.RegressionTarget, temp.Source

I further debugged and noticed that ClassInfo has 2 fields that are semantically tightly coupled but programmatically unrelated.

    /**
     * Names of classes referenced by this class in class refs and type signatures in the constant pool of the
     * classfile.
     */
    private Set<String> referencedClassNames;

    /** A list of ClassInfo objects for classes referenced by this class. */
    private ClassInfoList referencedClasses;

referencedClasses is generated from scratch even if referencedClassNames is already populated.
referencedClasses doesn't have temp.Source, but referencedClassNames does.

I think io.github.classgraph.ScanResult.indexResourcesAndClassInfo() should utilize referencedClassNames.

I attached a full log from verbose() and a failing JUnit 5 test case because of this bug.

log.txt
ReferencedClassTestCase.txt

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