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

get Class package and location returns null when use <context:load-time-weaver/> [SPR-14736] #19302

Open
spring-projects-issues opened this issue Sep 20, 2016 · 2 comments
Labels
type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Sep 20, 2016

jasperMin opened SPR-14736 and commented

Recently, I use "context:load-time-weaver/" config to support @Configurable annotation in my project.I found serious problems below when I trace the errors in my project.
1.XXX.class.getPackage() returns null
2.XXX.class.getProtectionDomain().getCodeSource().getLocation() returns null
These problems disappear when I don't use "context:load-time-weaver/".
The code "XXX.class.getPackage()" is used in many dependencies such as the static method in com.mysql.jdbc.Util:

packageName = MultiHostConnectionProxy.class.getPackage().getName();

The null result of Class.getPackage() causes NullPointerException.


No further details from SPR-14736

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 20, 2016

Juergen Hoeller commented

Note that Class.getPackage() is allowed to return {{null}: https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getPackage()

This is also why we do not rely on Class.getPackage() within our own codebase. It's arguably a bug that MySQL relies on that method to deliver a non-null result; instead, it should extract the package name from the fully-qualified class name which is the only safe option there.

As for our own load-time weaving exposing the package and protection domain there, that's worth considering as an improvement.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 20, 2016

jasperMin commented

I did create a bug for Mysql :http://bugs.mysql.com/bug.php?id=83052
And, I hope this improvement could be released soon, best in next version. Haaa!
Cause we can't expect all the dependencies won't rely on the non-null result of

Class.getpackage()

.
THX!

@spring-projects-issues spring-projects-issues added the type: enhancement label Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement
Projects
None yet
Development

No branches or pull requests

1 participant