You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ma...@apache.org on 2021/09/21 15:42:03 UTC

[pinot] branch master updated: Fix classpath with plugins java 8 (#7400)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 9224590  Fix classpath with plugins java 8 (#7400)
9224590 is described below

commit 92245902ed2e3010e0d6ec551ace2cff34e856f4
Author: Ken Krugler <ke...@transpac.com>
AuthorDate: Tue Sep 21 08:41:43 2021 -0700

    Fix classpath with plugins java 8 (#7400)
    
    * First cut at fixing up Hadoop batch segment generation job
    
    * Sync with upstream
    
    * Revert to previous behavior with pre-Java 9 JREs
---
 .../apache/pinot/spi/plugin/PluginClassLoader.java | 43 ++++++++++++++++++----
 1 file changed, 35 insertions(+), 8 deletions(-)

diff --git a/pinot-spi/src/main/java/org/apache/pinot/spi/plugin/PluginClassLoader.java b/pinot-spi/src/main/java/org/apache/pinot/spi/plugin/PluginClassLoader.java
index 98305f8..dda1cf8 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/plugin/PluginClassLoader.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/plugin/PluginClassLoader.java
@@ -19,6 +19,7 @@
 package org.apache.pinot.spi.plugin;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.Enumeration;
@@ -31,20 +32,33 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
 public class PluginClassLoader extends URLClassLoader {
 
   private final ClassLoader _classLoader;
+  private Method _addUrlMethod = null;
 
   public PluginClassLoader(URL[] urls, ClassLoader parent) {
     super(urls, parent);
     _classLoader = PluginClassLoader.class.getClassLoader();
+    
+    /**
+     * ClassLoader in java9+ does not extend URLClassLoader.
+     * If the class is not found in the parent classloader,
+     * it will be found in this classloader via findClass().
+     *
+     * @see https://bit.ly/2WROm1s
+     */
+
+    if (_classLoader instanceof URLClassLoader) {
+      try {
+        _addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
+      } catch (NoSuchMethodException e) {
+        //this should never happen
+        ExceptionUtils.rethrow(e);
+      }
+      
+      _addUrlMethod.setAccessible(true);
+    }
+
     for (URL url : urls) {
       try {
-        /**
-         * ClassLoader in java9+ does not extend URLClassLoader.
-         * If the class is not found in the parent classloader,
-         * it will be found in this classloader via findClass().
-         *
-         * @see https://community.oracle.com/tech/developers/discussion/4011800/base-classloader-no-longer-from
-         * -urlclassloader
-         */
         addURL(url);
       } catch (Exception e) {
         ExceptionUtils.rethrow(e);
@@ -53,6 +67,19 @@ public class PluginClassLoader extends URLClassLoader {
   }
 
   @Override
+  protected void addURL(URL url) {
+    if (_addUrlMethod != null) {
+      try {
+        _addUrlMethod.invoke(_classLoader, url);
+      } catch (Exception e) {
+        ExceptionUtils.rethrow(e);
+      }
+    } else {
+      super.addURL(url);
+    }
+  }
+
+  @Override
   protected Class<?> loadClass(String name, boolean resolve)
       throws ClassNotFoundException {
     // has the class loaded already?

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org