This is an automated email from the ASF dual-hosted git repository.

ifesdjeen pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/trunk by this push:
     new c55d727  Fix in-JVM dtest failures on java 11 as the system 
ClassLoader is not a URLClassLoader as of java 9
c55d727 is described below

commit c55d727bbe8d66e87497d6c8b6301a767b11bb4c
Author: David Capwell <dcapw...@gmail.com>
AuthorDate: Thu Sep 19 16:23:29 2019 -0700

    Fix in-JVM dtest failures on java 11 as the system ClassLoader is not a 
URLClassLoader as of java 9
    
    Patch by David Capwell, reviewed by Jon Meredith and Alex Petrov for 
CASSANDRA-15329.
---
 .../cassandra/distributed/impl/Versions.java       | 27 ++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git 
a/test/distributed/org/apache/cassandra/distributed/impl/Versions.java 
b/test/distributed/org/apache/cassandra/distributed/impl/Versions.java
index dba1c13..c75816b 100644
--- a/test/distributed/org/apache/cassandra/distributed/impl/Versions.java
+++ b/test/distributed/org/apache/cassandra/distributed/impl/Versions.java
@@ -21,7 +21,7 @@ package org.apache.cassandra.distributed.impl;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
-import java.net.URLClassLoader;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -40,7 +40,30 @@ import org.apache.cassandra.utils.FBUtilities;
 public class Versions
 {
     private static final Logger logger = 
LoggerFactory.getLogger(Versions.class);
-    public static Version CURRENT = new 
Version(FBUtilities.getReleaseVersionString(), 
((URLClassLoader)Versions.class.getClassLoader()).getURLs());
+    public static Version CURRENT = new 
Version(FBUtilities.getReleaseVersionString(), getClassPath());
+
+    private static URL[] getClassPath()
+    {
+        // In Java 9 the default system ClassLoader got changed from 
URLClassLoader to AppClassLoader which
+        // does not extend URLClassLoader nor does it give access to the class 
path array.
+        // Java requires the system property 'java.class.path' to be setup 
with the classpath seperated by :
+        // so this logic parses that string into the URL[] needed to build 
later
+        String cp = System.getProperty("java.class.path");
+        assert cp != null && !cp.isEmpty();
+        String[] split = cp.split(File.pathSeparator);
+        assert split.length > 0;
+        URL[] urls = new URL[split.length];
+        try
+        {
+            for (int i = 0; i < split.length; i++)
+                urls[i] = Paths.get(split[i]).toUri().toURL();
+        }
+        catch (MalformedURLException e)
+        {
+            throw new RuntimeException(e);
+        }
+        return urls;
+    }
 
     public enum Major
     {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to