Issue Details (XML | Word | Printable)

Key: OPENJPA-646
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Kevin Sutter
Reporter: Kevin Sutter
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

JDK problems with defineClass and enum class types

Created: 27/Jun/08 04:42 PM   Updated: 08/Sep/08 08:12 PM
Return to search
Component/s: kernel
Affects Version/s: 1.2.0
Fix Version/s: 1.2.1, 1.3.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works openjpa-646.patch 2008-06-27 04:52 PM Kevin Sutter 2 kB
Zip Archive Licensed for inclusion in ASF works pmr.zip 2008-06-27 04:49 PM Kevin Sutter 245 kB
Issue Links:
Reference
 

Resolution Date: 08/Sep/08 08:12 PM


 Description  « Hide
This Issue was first presented on our dev mailing list:

http://www.nabble.com/Sun-JDK-problem-with-duplicate-annotations-td18101863.html

I have also shared some additional experiences with Abe to get his views, but haven't heard anything back yet. So, I will create this JIRA Issue and work it from there.

The original problem was limited to the Sun JDK. But, in a soon-to-be-available update to the IBM JDK, the same problem surfaces. At least the same exception is presented. The actual call stack is different due to the different Sun and IBM packages, but it's a similar problem.

Basically, we are having a problem with our TempClassLoader attempting to use the defineClass() method on the CascadeType enum class. Our javax.persistence.CascadeType version doesn't experience this problem because we use Class.forName() to load the javax classes. In this scenario, I have an alt.persistence.CascadeType that falls into our normal class definition processing and attempts to use defineClass(). This method invocation completes okay. But, later when our code attempts to access the metadata associated with this type, we get the ArrayStoreException from the JDK.

I will post both a simple project that reproduces the problem as well as a "hack" patch that gets us around the problem. I also have a PMR opened against the IBM JDK to see if they can help resolve it.

Kevin


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Kevin Sutter added a comment - 27/Jun/08 04:49 PM
File pmr.zip is a simplified version of the problem that I put together for the IBM JDK problem report. To reproduce the problem, you have to build a jar file for this project and run the testcase with the -javaagent parameter. Or, you could just point the javaagent at the OpenJPA runtime jar file and use the "real" TempClassLoader implementation. Either way, you should be able to reproduce the problem.

Kevin Sutter made changes - 27/Jun/08 04:49 PM
Field Original Value New Value
Attachment pmr.zip [ 12384846 ]
Kevin Sutter added a comment - 27/Jun/08 04:52 PM
This hack of a patch just modifies our TempClassLoader implementation to treat enum class types like annotation class types and use the Class.forName() mechanism to load the class instead of the defineClass() mechanism. Until I get educated on what exactly is wrong with our current processing, I don't want to commit this change. But, in case someone runs into this situation, this is a potential workaround.

Kevin Sutter made changes - 27/Jun/08 04:52 PM
Attachment openjpa-646.patch [ 12384847 ]
Michael Dick added a comment - 30/Jul/08 04:20 PM
Moving to next release

Michael Dick made changes - 30/Jul/08 04:20 PM
Fix Version/s 1.2.0 [ 12313102 ]
Fix Version/s 1.3.0 [ 12313326 ]
Fix Version/s 1.2.1 [ 12313328 ]
Kevin Sutter made changes - 31/Jul/08 10:39 PM
Link This issue relates to OPENJPA-672 [ OPENJPA-672 ]
Kevin Sutter added a comment - 31/Jul/08 10:42 PM
I accidentally opened a new Issue for this same problem (OPENJPA-672). Just to get this Issue up to date, here are some of the details from that new Issue:

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)
                       el.getAnnotation(PersistentCollection.class));

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

Enough detail for now. Comments and suggestions are welcome.

Repository Revision Date User Message
ASF #686069 Thu Aug 14 22:36:22 UTC 2008 kwsutter OPENJPA-646. Integrating the original patch which bypasses the enum types in our TemporaryClassLoader.
Files Changed
MODIFY /openjpa/branches/1.2.x/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java

Repository Revision Date User Message
ASF #693233 Mon Sep 08 20:11:35 UTC 2008 kwsutter OPENJPA-646. Migrate this change from the 1.2.x branch to trunk.
Files Changed
MODIFY /openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java

Kevin Sutter added a comment - 08/Sep/08 08:12 PM
Resolved in the 1.2.x branch and 1.3.0 trunk.

Kevin Sutter made changes - 08/Sep/08 08:12 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]