openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r1671821 - /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
Date Tue, 07 Apr 2015 11:54:17 GMT
Author: struberg
Date: Tue Apr  7 11:54:17 2015
New Revision: 1671821

URL: http://svn.apache.org/r1671821
Log:
OPENJPA-2575 temporary set TCCL to _tmpClassloader

This prevents using the wrong ClassLoader during OpenJPA boostrap
which might lead to mem leaks.

Txs to rmannibucau for the report and fix!

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

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java?rev=1671821&r1=1671820&r2=1671821&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
Tue Apr  7 11:54:17 2015
@@ -21,11 +21,13 @@ package org.apache.openjpa.enhance;
 import java.io.ByteArrayInputStream;
 import java.lang.instrument.ClassFileTransformer;
 import java.lang.instrument.IllegalClassFormatException;
+import java.security.AccessController;
 import java.security.ProtectionDomain;
 import java.util.Set;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.util.J2DoPrivHelper;
 import org.apache.openjpa.lib.util.Localizer;
 import org.apache.openjpa.lib.util.Options;
 import org.apache.openjpa.meta.MetaDataRepository;
@@ -142,18 +144,24 @@ public class PCClassFileTransformer
             if (enhance != Boolean.TRUE)
                 return null;
 
-            PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(),
-                new Project().loadClass(new ByteArrayInputStream(bytes),
-                    _tmpLoader), _repos);
-            enhancer.setAddDefaultConstructor(_flags.addDefaultConstructor);
-            enhancer.setEnforcePropertyRestrictions
-                (_flags.enforcePropertyRestrictions);
-
-            if (enhancer.run() == PCEnhancer.ENHANCE_NONE)
-                return null;
-            BCClass pcb = enhancer.getPCBytecode();
-            returnBytes = AsmAdaptor.toByteArray(pcb, pcb.toByteArray());
-            return returnBytes;
+            ClassLoader oldLoader = AccessController.doPrivileged(J2DoPrivHelper.getContextClassLoaderAction());
+            AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction(_tmpLoader));
+            try {
+                PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(),
+                        new Project().loadClass(new ByteArrayInputStream(bytes),
+                                _tmpLoader), _repos);
+                enhancer.setAddDefaultConstructor(_flags.addDefaultConstructor);
+                enhancer.setEnforcePropertyRestrictions
+                        (_flags.enforcePropertyRestrictions);
+
+                if (enhancer.run() == PCEnhancer.ENHANCE_NONE)
+                    return null;
+                BCClass pcb = enhancer.getPCBytecode();
+                returnBytes = AsmAdaptor.toByteArray(pcb, pcb.toByteArray());
+                return returnBytes;
+            } finally {
+                AccessController.doPrivileged(J2DoPrivHelper.setContextClassLoaderAction(oldLoader));
+            }
         } catch (Throwable t) {
             _log.warn(_loc.get("cft-exception-thrown", className), t);
             if (t instanceof RuntimeException)



Mime
View raw message