You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2016/03/31 10:13:19 UTC

svn commit: r1737188 - /db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java

Author: kahatlen
Date: Thu Mar 31 08:13:19 2016
New Revision: 1737188

URL: http://svn.apache.org/viewvc?rev=1737188&view=rev
Log:
DERBY-6881: Test failures with JDK 9-ea b111

ClassLoaderTestSetup casts the context class loader to URLClassLoader
in order to create a new URLClassLoader with the same URLs as the
original class loader. In JDK 9, the context class loader is no longer
a URLClassLoader after JEP 261. This code now results in a
ClassCastException.

The point of ClassLoaderTestSetup is to change the context class
loader to something which is not the system class loader. It does not
have to be a clone of the original context class loader. This patch
therefore changes ClassLoaderTestSetup so that it sets the context
class loader to an empty URLClassLoader which wraps the system class
loader. This avoids the unreliable cast and the resulting
ClassCastException.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java?rev=1737188&r1=1737187&r2=1737188&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/ClassLoaderTestSetup.java Thu Mar 31 08:13:19 2016
@@ -24,7 +24,6 @@ import java.net.URLClassLoader;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import junit.framework.Test;
-import org.apache.derbyTesting.functionTests.tests.upgradeTests.UpgradeClassLoader;
 
 /**
  * A decorator that changes the context class loader for the current
@@ -45,15 +44,9 @@ public class ClassLoaderTestSetup extend
         super(test);
     }
 
-    private static ClassLoader makeClassLoader(final ClassLoader old) {
-        return AccessController.doPrivileged(
-            new PrivilegedAction<URLClassLoader>() {
-                @Override
-                public URLClassLoader run() {
-                        URL[] jars = ((URLClassLoader)old).getURLs();
-                        return new URLClassLoader(jars, null);
-                }
-            });
+    private static ClassLoader makeClassLoader() {
+        PrivilegedAction<ClassLoader> pa = () -> new URLClassLoader(new URL[0]);
+        return AccessController.doPrivileged(pa);
     }
 
     @Override
@@ -61,7 +54,7 @@ public class ClassLoaderTestSetup extend
         super.setUp();
         TestConfiguration.getCurrent().shutdownEngine();
         oldLoader = getThreadLoader();
-        setThreadLoader(makeClassLoader(oldLoader));
+        setThreadLoader(makeClassLoader());
     }
 
     @Override