You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by kw...@apache.org on 2008/09/08 22:11:36 UTC
svn commit: r693233 -
/openjpa/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/TemporaryClassLoader.java
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
+ }
}