Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Methods with generic parameters cannot be loaded #694

Closed
freya022 opened this issue Jun 28, 2022 · 3 comments
Closed

Methods with generic parameters cannot be loaded #694

freya022 opened this issue Jun 28, 2022 · 3 comments

Comments

@freya022
Copy link
Contributor

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

@lukehutch
Copy link
Member

Hi @freya022,

Thanks for the bug report and reproducer testcase.

I think I fixed the bug, but please check whether it works for you, and please also look at the source code of my change to see if it works as you would expect it to.

Thank you!

@freya022
Copy link
Contributor Author

freya022 commented Jul 4, 2022

Hello, seems like the issue is fixed, I don't have any issue with the source changes. Thanks.

@freya022 freya022 closed this as completed Jul 4, 2022
@lukehutch
Copy link
Member

Thanks for taking a look, released in 4.8.148.

lukehutch added a commit that referenced this issue Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants