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

jeagles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tez.git


The following commit(s) were added to refs/heads/master by this push:
     new 47f0f35  TEZ-3860. JDK9: ReflectionUtils may not use URLClassLoader
47f0f35 is described below

commit 47f0f354ab38ea2b96ed6ed008f158527b30903f
Author: László Bodor <[email protected]>
AuthorDate: Mon Nov 18 13:24:32 2019 -0600

    TEZ-3860. JDK9: ReflectionUtils may not use URLClassLoader
    
    Signed-off-by: Jonathan Eagles <[email protected]>
---
 .../org/apache/tez/common/ReflectionUtils.java     |  8 ++-
 .../java/org/apache/tez/common/TezClassLoader.java | 62 ++++++++++++++++++++++
 .../org/apache/tez/client/TestTezClientUtils.java  | 12 ++---
 .../java/org/apache/tez/dag/app/DAGAppMaster.java  |  3 +-
 4 files changed, 76 insertions(+), 9 deletions(-)

diff --git a/tez-api/src/main/java/org/apache/tez/common/ReflectionUtils.java 
b/tez-api/src/main/java/org/apache/tez/common/ReflectionUtils.java
index 4d89ed4..9f7c5d3 100644
--- a/tez-api/src/main/java/org/apache/tez/common/ReflectionUtils.java
+++ b/tez-api/src/main/java/org/apache/tez/common/ReflectionUtils.java
@@ -122,9 +122,9 @@ public class ReflectionUtils {
 
   @Private
   public static synchronized void addResourcesToSystemClassLoader(List<URL> 
urls) {
-    URLClassLoader sysLoader = 
(URLClassLoader)ClassLoader.getSystemClassLoader();
+    ClassLoader sysLoader = getSystemClassLoader();
     if (sysClassLoaderMethod == null) {
-      Class<?> sysClass = URLClassLoader.class;
+      Class<?> sysClass = TezClassLoader.class;
       Method method;
       try {
         method = sysClass.getDeclaredMethod("addURL", parameters);
@@ -148,4 +148,8 @@ public class ReflectionUtils {
       }
     }
   }
+
+  private static ClassLoader getSystemClassLoader() {
+    return TezClassLoader.getInstance();
+  }
 }
diff --git a/tez-api/src/main/java/org/apache/tez/common/TezClassLoader.java 
b/tez-api/src/main/java/org/apache/tez/common/TezClassLoader.java
new file mode 100644
index 0000000..2679efa
--- /dev/null
+++ b/tez-api/src/main/java/org/apache/tez/common/TezClassLoader.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tez.common;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Arrays;
+
+public class TezClassLoader extends URLClassLoader {
+  private static TezClassLoader INSTANCE;
+
+  static {
+    INSTANCE = AccessController.doPrivileged(new 
PrivilegedAction<TezClassLoader>() {
+      ClassLoader sysLoader = TezClassLoader.class.getClassLoader();
+
+      public TezClassLoader run() {
+        return new TezClassLoader(
+            sysLoader instanceof URLClassLoader ? ((URLClassLoader) 
sysLoader).getURLs() : extractClassPathEntries(),
+            sysLoader);
+      }
+    });
+  }
+
+  public TezClassLoader(URL[] urls, ClassLoader classLoader) {
+    super(urls, classLoader);
+  }
+
+  public void addURL(URL url) {
+    super.addURL(url);
+  }
+
+  public static TezClassLoader getInstance() {
+    return INSTANCE;
+  }
+
+  private static URL[] extractClassPathEntries() {
+    String pathSeparator = System.getProperty("path.separator");
+    String[] classPathEntries = 
System.getProperty("java.class.path").split(pathSeparator);
+    URL[] cp = Arrays.asList(classPathEntries).stream().map(s -> {
+      try {
+        return new URL("file://" + s);
+      } catch (MalformedURLException e) {
+        throw new RuntimeException(e);
+      }
+    }).toArray(URL[]::new);
+    return cp;
+  }
+}
diff --git 
a/tez-api/src/test/java/org/apache/tez/client/TestTezClientUtils.java 
b/tez-api/src/test/java/org/apache/tez/client/TestTezClientUtils.java
index 7ff8125..581d722 100644
--- a/tez-api/src/test/java/org/apache/tez/client/TestTezClientUtils.java
+++ b/tez-api/src/test/java/org/apache/tez/client/TestTezClientUtils.java
@@ -27,7 +27,6 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
-import java.net.URLClassLoader;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -60,6 +59,7 @@ import org.apache.hadoop.yarn.api.records.Resource;
 import org.apache.hadoop.yarn.conf.YarnConfiguration;
 import org.apache.hadoop.yarn.exceptions.YarnException;
 import org.apache.hadoop.yarn.util.Records;
+import org.apache.tez.common.TezClassLoader;
 import org.apache.tez.common.security.JobTokenIdentifier;
 import org.apache.tez.common.security.JobTokenSecretManager;
 import org.apache.tez.common.security.TokenCache;
@@ -131,9 +131,9 @@ public class TestTezClientUtils {
   /**
    *
    */
-  @Test (timeout=10000)
+  @Test (timeout=20000)
   public void validateSetTezJarLocalResourcesDefinedExistingDirectory() throws 
Exception {
-    URL[] cp = ((URLClassLoader)ClassLoader.getSystemClassLoader()).getURLs();
+    URL[] cp = TezClassLoader.getInstance().getURLs();
     StringBuffer buffer = new StringBuffer();
     for (URL url : cp) {
       buffer.append(url.toExternalForm());
@@ -171,7 +171,7 @@ public class TestTezClientUtils {
    */
   @Test (timeout=5000)
   public void validateSetTezJarLocalResourcesDefinedExistingDirectoryIgnored() 
throws Exception {
-    URL[] cp = ((URLClassLoader)ClassLoader.getSystemClassLoader()).getURLs();
+    URL[] cp = TezClassLoader.getInstance().getURLs();
     StringBuffer buffer = new StringBuffer();
     for (URL url : cp) {
       buffer.append(url.toExternalForm());
@@ -190,9 +190,9 @@ public class TestTezClientUtils {
    * 
    * @throws Exception
    */
-  @Test (timeout=5000)
+  @Test (timeout=20000)
   public void 
validateSetTezJarLocalResourcesDefinedExistingDirectoryIgnoredSetToFalse() 
throws Exception {
-    URL[] cp = ((URLClassLoader)ClassLoader.getSystemClassLoader()).getURLs();
+    URL[] cp = TezClassLoader.getInstance().getURLs();
     StringBuffer buffer = new StringBuffer();
     for (URL url : cp) {
       buffer.append(url.toExternalForm());
diff --git a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java 
b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
index 2d2f23d..6636fb6 100644
--- a/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
+++ b/tez-dag/src/main/java/org/apache/tez/dag/app/DAGAppMaster.java
@@ -115,6 +115,7 @@ import org.apache.hadoop.yarn.util.SystemClock;
 import org.apache.tez.common.AsyncDispatcher;
 import org.apache.tez.common.AsyncDispatcherConcurrent;
 import org.apache.tez.common.GcTimeUpdater;
+import org.apache.tez.common.TezClassLoader;
 import org.apache.tez.common.TezCommonUtils;
 import org.apache.tez.common.TezConverterUtils;
 import org.apache.tez.common.TezUtilsInternal;
@@ -1404,7 +1405,7 @@ public class DAGAppMaster extends AbstractService {
   }
 
   private static Path findLocalFileForResource(String fileName) {
-    URL localResource = 
ClassLoader.getSystemClassLoader().getResource(fileName);
+    URL localResource = TezClassLoader.getInstance().getResource(fileName);
     if (localResource == null) return null;
     return new Path(localResource.getPath());
   }

Reply via email to