[ 
https://issues.apache.org/jira/browse/OCM-6?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13416919#comment-13416919
 ] 

Ard Schrijvers commented on OCM-6:
----------------------------------

Hello Eduardo,

Are you now testing against OCM 2.0.0? 

The solution you found is a workaround which V.W. already pointed out, which is 
still pretty unfortunate: What if you have multiple webapps that concurrently 
use this ReflectionUtils?

Afaics, it would make much more sense to have

1) public static Class forName(String clazz) use 
Thread.currentThread.getContextClassLoader()
2) Add a new method static Class forName(String clazz, ClassLoader classLoader)
3) Remove the evil private static ClassLoader classLoader = 
ReflectionUtils.class.getClassLoader(); 

WDYT? Can you test this with the 2.0.1-SNAPSHOT for your usecase if I make this 
change?

Regards Ard
                
> ClassDescriptor ReflectionUtils ClassLoader Defect
> --------------------------------------------------
>
>                 Key: OCM-6
>                 URL: https://issues.apache.org/jira/browse/OCM-6
>             Project: Jackrabbit OCM
>          Issue Type: Bug
>         Environment: JVM 1.6.0.6/Windows XP SP2/Netbeans 6.2 Beta
>            Reporter: V. W.
>         Attachments: TestCase.zip
>
>
> I have stumbuled on a bug in the interaction between ClassDescriptor and 
> ReflectionUtils classes:
> 1. ClassDescriptor.validateClassName() uses ReflectionUtils.forName(String) 
> to resolve an annotated class by its name
> 2. ReflectionUtils is an evil stateful statics-based singleton. It has a 
> field of a ClassLoader, which by default is the one that loaded the 
> ReflectionUtils. The method forName(String) uses this ClassLoader to resolve 
> the annotated class.
> The problem is that the ClassDescriptor assumses that the annotated class 
> comes from a global ClassLoader (the one that loaded the jars), which is not 
> always correct. The workaround is to manually set the ReflectionUtils 
> ClassLoader field for it to use the correct ClassLoader.
> I've found this bug while working with NetBeans, writing a small Scala 
> application and using ScalaTest TestNG integration for testing. Apparantly 
> many ClassLoader need to by involved to run a single test.
> I've created a unit test (java only, libraries included) to reproduce the bug.
> The best solution would be for the ClassDescriptor to use a Class reference 
> (the Class contains its ClassLoader reference) instead of just a class-name 
> or at least pair every class-name with its ClassLoader.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to