Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
MappedPropertyDescriptor#reLoadClass() possible NPE / odd code
private Class reLoadClass() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // Try the context class loader if (classLoader != null) { try { return classLoader.loadClass(className); } catch (Throwable t) { // ignore } } // Try this class's class loader try { return classLoader.loadClass(className); } catch (Throwable t) { return null; } }
The second call to classLoader.loadClass(className) is likely to fail with NPE - if it is ever called.
The comments suggest that the second loadClass() invocation should be done using a different class loader, however this is not done.
Does the code really want to try loading the class twice using the same classloader?
This is what will happen if the initial loadClass() fails.
Another problem with the code is that it swallows Throwable.
It would be better to catch just the expected Exceptions - or even Exception, but not Throwable.