From 04bb0664750212b332720e87b5f273310a8ed1f6 Mon Sep 17 00:00:00 2001 From: Jeremy Bauer Date: Wed, 17 Mar 2010 17:58:40 +0000 Subject: [PATCH] OPENJPA-1410 Disable loading of dynamic enhancement agent if OpenJPA is not loaded with the system classloader. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@924395 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/enhance/InstrumentationFactory.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java index 37b9983f8..2a0d0cce6 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/InstrumentationFactory.java @@ -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() { 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) {