activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jan Stette (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance
Date Mon, 18 Jun 2007 17:18:33 GMT

    [ https://issues.apache.org/activemq/browse/AMQ-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_39444
] 

Jan Stette commented on AMQ-1229:
---------------------------------

I just encountered the same issue in 4.1.1.  Looking at the patched version above, I think
it subtly changes the behavior of the newInstance() method.  The old version would first try
to load the class with the thread context classloader, then if that failed to load it, it
would try the FindFactory class' own classloader.  As patched above, it will only ever try
the first classloaders it finds.  I don't know what is the intended behavior, just want to
make sure that the change is what is actually wanted.

I've patched this myself like this instead:

        Class clazz = null;
        try {
			ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
			if (contextClassLoader != null) {
	            clazz = contextClassLoader.loadClass(className);
			}
        } catch (ClassNotFoundException e) {
            ; // Ignore this here, try this class' class loader first.
        }
        if (clazz == null) {
			clazz = FactoryFinder.class.getClassLoader().loadClass(className);
		}

This means that if the thread context class loader is set, but doesn't find the class, it
will try the next classloader as well.



> Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance
> --------------------------------------------------------------------------------
>
>                 Key: AMQ-1229
>                 URL: https://issues.apache.org/activemq/browse/AMQ-1229
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Transport
>            Reporter: John McLeroy
>             Fix For: 5.0.0
>
>         Attachments: FactoryFinder.java
>
>   Original Estimate: 5 minutes
>  Remaining Estimate: 5 minutes
>
> org.apache.activemq.util.FactoryFinder.doFindFactoryProperies() correctly consults the
current class's loader if Thread.currentThread().getContextClassLoader() is null:
>         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
>         if (classLoader == null) classLoader = getClass().getClassLoader();
> newInstance(), however, generates a null pointer exception if Thread.currentThread().getContextClassLoader()
is null:
>         Class clazz;
>         try {
>             clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
>         } catch (ClassNotFoundException e) {
>             clazz = FactoryFinder.class.getClassLoader().loadClass(className);
>         }

-- 
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