Review request (Resend) - bug 7147060 com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java doesn't run in agentvm mode

Eric Wang yiming.wang at oracle.com
Mon Jul 9 01:13:45 PDT 2012


Hi Sean,

Looks that security-dev alias rejected my previous mail as i was not the 
member of it. so I resent this fix again.
Can you please help to review? Thanks!

Eric
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 7147060.zip
Type: application/x-zip-compressed
Size: 82921 bytes
Desc: not available
Url : http://mail.openjdk.java.net/pipermail/security-dev/attachments/20120709/b23e2cd0/7147060.zip 
-------------- next part --------------
--- old/test/ProblemList.txt	2012-07-05 15:57:49.477164126 +0800
+++ new/test/ProblemList.txt	2012-07-05 15:57:45.177070426 +0800
@@ -290,9 +290,6 @@
 # 7177556
 com/sun/crypto/provider/KeyFactory/TestProviderLeak.java        generic-all
 
-# 7147060
-com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java	generic-all
-
 # Failing on Solaris i586, 3/9/2010, not a -samevm issue (jdk_security3)
 sun/security/pkcs11/Secmod/AddPrivateKey.java                   solaris-i586
 sun/security/pkcs11/ec/ReadCertificates.java                    generic-all
-------------- next part --------------
--- old/test/com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java	2012-07-05 15:57:56.799140287 +0800
+++ new/test/com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java	2012-07-05 15:57:54.790043435 +0800
@@ -39,7 +39,7 @@
 
 public class ClassLoaderTest {
 
-    private final static String BASE = System.getProperty("test.src", "./");
+    private final static String BASE = System.getProperty("test.classes", "./");
 
     public static void main(String[] args) throws Exception {
 
@@ -50,15 +50,26 @@
         URLClassLoader ucl = new URLClassLoader(urls);
         Class c = ucl.loadClass("MyTransform");
         Constructor cons = c.getConstructor();
-        Object o = cons.newInstance();
-        // Apache code swallows the ClassNotFoundExc, so we need to
-        // check if the Transform has already been registered by registering
-        // it again and catching an AlgorithmAlreadyRegisteredExc
+
+        Thread curThread = Thread.currentThread();
+        ClassLoader ctxLoader = curThread.getContextClassLoader();
+        ClassLoader loader = MyTransform.class.getClassLoader();
         try {
+            // In agentvm mode, the class MyTransform is loaded by the child of
+            // context ClassLoader of this thread. Replace context ClassLoader
+            // with its child to avoid ClassNotFoundException thrown from
+            // Transform.register(String, String) method.
+            curThread.setContextClassLoader(loader);
+            Object o = cons.newInstance();
+            // Apache code swallows the ClassNotFoundExc, so we need to
+            // check if the Transform has already been registered by registering
+            // it again and catching an AlgorithmAlreadyRegisteredExc
             Transform.register(MyTransform.URI, "MyTransform");
             throw new Exception("ClassLoaderTest failed");
         } catch (AlgorithmAlreadyRegisteredException e) {
             // test passed
+        } finally {
+            curThread.setContextClassLoader(ctxLoader);
         }
     }
 }


More information about the security-dev mailing list