openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dazey...@apache.org
Subject svn commit: r1827843 - /openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
Date Tue, 27 Mar 2018 15:28:04 GMT
Author: dazeydev
Date: Tue Mar 27 15:28:04 2018
New Revision: 1827843

URL: http://svn.apache.org/viewvc?rev=1827843&view=rev
Log:
OPENJPA-2575: temporary set TCCL to _tmpClassloader

This prevents using the wrong ClassLoader during OpenJPA bootstrap
which might lead to memory leaks.

Modified:
    openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java

Modified: openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java?rev=1827843&r1=1827842&r2=1827843&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
(original)
+++ openjpa/branches/2.2.x/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
Tue Mar 27 15:28:04 2018
@@ -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;
@@ -143,18 +145,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