openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwsut...@apache.org
Subject svn commit: r693233 - /openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java
Date Mon, 08 Sep 2008 20:11:36 GMT
Author: kwsutter
Date: Mon Sep  8 13:11:35 2008
New Revision: 693233

URL: http://svn.apache.org/viewvc?rev=693233&view=rev
Log:
OPENJPA-646.  Migrate this change from the 1.2.x branch to trunk.

Modified:
    openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java

Modified: openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java?rev=693233&r1=693232&r2=693233&view=diff
==============================================================================
--- openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java
(original)
+++ openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java
Mon Sep  8 13:11:35 2008
@@ -70,7 +70,10 @@
                 bout.write(b, 0, n))
                 ;
             byte[] classBytes = bout.toByteArray();
-            if (isAnnotation(classBytes))
+            // To avoid classloader issues with the JVM (Sun and IBM), we
+            // will not load Enums via the TemporaryClassLoader either.
+            // Reference JIRA Issue OPENJPA-646 for more information.
+            if (isAnnotation(classBytes) || isEnum(classBytes))
                 return Class.forName(name, resolve, getClass().
                     getClassLoader());
 
@@ -97,4 +100,16 @@
         int access = ConstantPoolTable.readUnsignedShort(b, idx);
         return (access & 0x2000) != 0; // access constant for annotation type
     }
+
+    /**
+     * Fast-parse the given class bytecode to determine if it is an
+     * enum class.
+     */
+    private static boolean isEnum(byte[] b) {
+        if (JavaVersions.VERSION < 5)
+            return false;
+        int idx = ConstantPoolTable.getEndIndex(b);
+        int access = ConstantPoolTable.readUnsignedShort(b, idx);
+        return (access & 0x4000) != 0; // access constant for enum type
+    }
 }



Mime
View raw message