You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Eduardo Mineo (JIRA)" <ji...@apache.org> on 2012/07/17 21:52:34 UTC

[jira] [Commented] (OCM-6) ClassDescriptor ReflectionUtils ClassLoader Defect

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

Eduardo Mineo commented on OCM-6:
---------------------------------

Hi,

even though this is an old thread, I've faced this very issue and found out a solution:

You can set OCM class loader by:

ReflectionUtils.setClassLoader(getClass().getClassLoader());

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