openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter (JIRA)" <>
Subject [jira] Created: (OPENJPA-672) Annotations, Enums, and our TemporaryClassLoader
Date Thu, 31 Jul 2008 22:28:31 GMT
Annotations, Enums, and our TemporaryClassLoader

                 Key: OPENJPA-672
             Project: OpenJPA
          Issue Type: Bug
          Components: lib
    Affects Versions: 1.1.0, 1.0.3, 1.0.2, 1.0.1, 1.0.0
            Reporter: Kevin Sutter
            Assignee: Kevin Sutter

I thought I had opened a JIRA for this dev forum discussion (,
but I guess not.

I have been tracking this problem via a problem report with the IBM JDK team (since I was
able to eventually reproduce the same problem with both the Sun JDK and IBM JDK).  So far,
we have not determined a definite problem with the JDK processing of annotations and enums.

Here's a summary of the basic problem (from the dev forum post):

The scenario is that I have annotations doubly defined (ie. javax.persistence.OneToMany and
alt.persistence.OneToMany).  A single entity might utilize both of them, like this:

    Collection<Fill> buySideFills;

This results in the following callstack snippet when running with the -javaagent version of
enhancement and the Sun JDK (fixpack 15):

java.lang.ArrayStoreException: sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy
    at sun.reflect.annotation.AnnotationParser.parseEnumArray(
    at sun.reflect.annotation.AnnotationParser.parseArray(
    at sun.reflect.annotation.AnnotationParser.parseMemberValue(
    at sun.reflect.annotation.AnnotationParser.parseAnnotation(
    at sun.reflect.annotation.AnnotationParser.parseAnnotations2(
    at sun.reflect.annotation.AnnotationParser.parseAnnotations(
    at java.lang.reflect.Field.declaredAnnotations(
    at java.lang.reflect.Field.getDeclaredAnnotations(
    at java.lang.reflect.AccessibleObject.getAnnotations(
    at org.apache.openjpa.lib.util.J2DoPriv5Helper$
    at Method)
    at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.annotated(
    at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.getAccessType(
    at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.getAccessType(
    at org.apache.openjpa.meta.AbstractMetaDataDefaults.populate(
    at org.apache.openjpa.persistence.PersistenceMetaDataDefaults.populate(
    at org.apache.openjpa.meta.MetaDataRepository.addMetaData(
    at org.apache.openjpa.meta.MetaDataRepository.addMetaData(
    at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.getMetaData(
    at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parseClassAnnotations(
    at org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.parse(
    at org.apache.openjpa.persistence.PersistenceMetaDataFactory.load(
    at org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(
    at org.apache.openjpa.meta.MetaDataRepository.getMetaData(
    at org.apache.openjpa.enhance.PCEnhancer.<init>(
    at org.apache.openjpa.enhance.PCEnhancer.<init>(
    at org.apache.openjpa.enhance.PCClassFileTransformer.transform0(
    at org.apache.openjpa.enhance.PCClassFileTransformer.transform(
    at sun.instrument.TransformerManager.transform(
    at sun.instrument.InstrumentationImpl.transform(
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(
    at Method)
    at java.lang.ClassLoader.loadClass(
    at sun.misc.Launcher$AppClassLoader.loadClass(
    at java.lang.ClassLoader.loadClass(
    at java.lang.ClassLoader.loadClassInternal(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at org.apache.openjpa.meta.MetaDataRepository.classForName(
    at org.apache.openjpa.meta.MetaDataRepository.loadPersistentTypes(
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(
    at org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(
    at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(
    at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(
    at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(

>From working with the JDK team, the problem is surfacing because the ClassLoader (AppClassLoader)
that is used to load the Enum type when the alt.persistence.OneToMany is loaded is not the
same ClassLoader (TemporaryClassLoader) when the Enum type is loaded by our enhancement processing.
 Thus, the AnnotationTypeMismatchExceptionProxy from the JDK.

One way to workaround the problem is to add a test for Enum types in the TemporaryClassLoader
and use the AppClassLoader in this case (much like we do for Annotation types):

            if (isAnnotation(classBytes) || isEnum(classBytes))
                return Class.forName(name, resolve, getClass().getClassLoader());

The JDK team suggested removing the check for isAnnotation (and isEnum) altogether since that
resolved the simple testcase that I had put together for their benefit.  Unfortunately, that
doesn't work for our enhancement processing for a couple of reasons.  The _strats structure
in PersistentMetaDataDefaults depended on the org.apache.openjpa.persistence.PersistentCollection
class.  By removing the conditional above, then we had a mismatch in classloaders for this
data structure, much like the jdk problem.

I tried changing the key for this _strats structure to use the class name string instead of
the actual class instance.  This got us around our immediate concern, but eventually I hit
another JDK issue with mismatched classloaders when processing the annotations in AnnotationPersistentMetaDataParser:

                    parsePersistentCollection(fmd, (PersistentCollection)

The loading of this PersistentCollection.class used the AppClassLoader, so the lookup via
getAnnotation didn't find anything since the original annotation was loaded by the TemporaryClassLoader.
 Trying to get around this situation was creating some pretty ugly code.

So, I am leaning towards the original workaround as a "solution" with proper commenting. 
By allowing the AppClassLoader to load enum types (vs the TemporaryClassLoader), we would
"pollute" the AppClassLoader with left over enum classes.  This would seem to be a minor drawback.
 Of course, if we ever need to allow for the enhancement of enum classes, then we're up a

Enough detail for now.  Comments and suggestions are welcome.


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

View raw message