commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] Created: (BEANUTILS-336) MappedPropertyDescriptor#reLoadClass() possible NPE / odd code; also swallows Throwable
Date Tue, 17 Feb 2009 00:09:59 GMT
MappedPropertyDescriptor#reLoadClass() possible NPE / odd code; also swallows Throwable
---------------------------------------------------------------------------------------

                 Key: BEANUTILS-336
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-336
             Project: Commons BeanUtils
          Issue Type: Bug
          Components: Bean / Property Utils
            Reporter: Sebb


MappedPropertyDescriptor#reLoadClass() possible NPE / odd code

{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;
    }
}
{code}

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.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message