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

Bug fix for LocalUtil #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

moonfruit
Copy link

Previous LocalUtil.java makes below useless:
clazz = Thread.currentThread().getContextClassLoader().loadClass(remappedClassName);
Because of the next:
clazz = LocalUtil.class.getClassLoader().loadClass(remappedClassName);

@dmarginian
Copy link
Contributor

What bug is being fixed with this change? It appears to be a stylistic change that doesn't impact the results.

@moonfruit
Copy link
Author

moonfruit commented Apr 12, 2021

You can see this:

String remappedClassName = remappedDwrClassName(className);
Class<?> clazz = null;
try {
clazz = Thread.currentThread().getContextClassLoader().loadClass(remappedClassName);
} catch(ClassNotFoundException ex) {
// fall through
} catch(IllegalArgumentException ex) {
// Conform to JDK classloader behaviour where illegal classnames are handled as ClassNotFound
// fall through
}
try {
clazz = LocalUtil.class.getClassLoader().loadClass(remappedClassName);
} catch(IllegalArgumentException ex) {
// Conform to JDK classloader behaviour where illegal classnames are handled as ClassNotFound
throw new ClassNotFoundException(ex.getMessage(), ex);
}
return clazz;

the code run this:

clazz = LocalUtil.class.getClassLoader().loadClass(remappedClassName);

immediately after this:

clazz = Thread.currentThread().getContextClassLoader().loadClass(remappedClassName);

So even clazz = Thread.currentThread().getContextClassLoader().loadClass(remappedClassName) is successful returned, the program will also run clazz = LocalUtil.class.getClassLoader().loadClass(remappedClassName), this makes clazz = Thread.currentThread().getContextClassLoader().loadClass(remappedClassName) useless.
Or we can just run clazz = LocalUtil.class.getClassLoader().loadClass(remappedClassName) if this is you wanted, but I think not.

@dmarginian
Copy link
Contributor

Yes, thanks. I wonder if the first attempt is even needed. I would have to look into more but this change looks fine.

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

Successfully merging this pull request may close these issues.

None yet

2 participants