Author: jrbauer
Date: Wed Mar 17 17:58:40 2010
New Revision: 924395

URL: http://svn.apache.org/viewvc?rev=924395&view=rev
Log:
OPENJPA-1410 Disable loading of dynamic enhancement agent if OpenJPA is not 
loaded with the system classloader.

Modified:
    
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java

Modified: 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java
URL: 
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java?rev=924395&r1=924394&r2=924395&view=diff
==============================================================================
--- 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java
 (original)
+++ 
openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java
 Wed Mar 17 17:58:40 2010
@@ -79,8 +79,7 @@ public class InstrumentationFactory {
      * @return null if Instrumentation can not be obtained, or if any 
      * Exceptions are encountered.
      */
-    public static synchronized Instrumentation 
-        getInstrumentation(final Log log) {
+    public static synchronized Instrumentation getInstrumentation(final Log 
log) {
         if (_inst != null || !_dynamicallyInstall)
             return _inst;
 
@@ -90,6 +89,18 @@ public class InstrumentationFactory {
 
         AccessController.doPrivileged(new PrivilegedAction<Object>() {
             public Object run() {
+                // Dynamic agent enhancement should only occur when the 
OpenJPA library is 
+                // loaded using the system class loader.  Otherwise, the 
OpenJPA
+                // library may get loaded by separate, disjunct loaders, 
leading to linkage issues.
+                try {
+                    if (!InstrumentationFactory.class.getClassLoader().equals(
+                        ClassLoader.getSystemClassLoader())) {
+                        return null;
+                    }
+                } catch (Throwable t) {
+                    return null;
+                }
+                
                 // If we can't find the tools.jar, we can't load the agent.
                 File toolsJar = findToolsJar(log);
                 if (toolsJar == null) {


Reply via email to