You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "John McLeroy (JIRA)" <ji...@apache.org> on 2007/04/16 20:02:34 UTC

[jira] Created: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance

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
         Attachments: FactoryFinder.java

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.


[jira] Commented: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance

Posted by "Jan Stette (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Assigned: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned AMQ-1229:
--------------------------------

    Assignee: Claus Ibsen

> 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
>            Assignee: Claus Ibsen
>             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.


[jira] Resolved: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance

Posted by "James Strachan (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

James Strachan resolved AMQ-1229.
---------------------------------

       Resolution: Fixed
    Fix Version/s: 5.0.0

Patch applied, many thanks!

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


[jira] Assigned: (AMQ-1229) Thread.currentThread().getContextClassLoader() null in FactoryFinder.newInstance

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQ-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned AMQ-1229:
--------------------------------

    Assignee:     (was: Claus Ibsen)

Sorry I was looking at CAMEL-1301 that had a link to this one.

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