Skip to content

Methods with generic parameters cannot be loaded #694

@freya022

Description

@freya022

I am trying to load a method from a class with MethodInfo#loadClassAndGetMethod, but it's failing saying it didn't find the method, exception:

Exception in thread "main" java.lang.IllegalArgumentException: Method not found: com.freya02.botcommands.oldtests.ClassGraphBug.test
	at io.github.classgraph.MethodInfo.loadClassAndGetMethod(MethodInfo.java:849)
	at com.freya02.botcommands.oldtests.ClassGraphBug.main(ClassGraphBug.java:30)

The loading is failing because the method has a generic parameter, by debugging the internals i've found the parameter types used to find the method were wrong, if you have a single parameter which type is a generic, MethodInfo#loadParameterClasses returns the class the method is declared in, however, it should have returned the erasure of the generic parameter.

Here are the verbose logs as well as a reproducible example.
CG-logs.log
ClassGraphBug.zip

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