pig-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkol...@apache.org
Subject svn commit: r1859620 - in /pig/trunk: src/org/apache/pig/impl/plan/Operator.java test/org/apache/pig/test/TestPigServer.java test/org/apache/pig/test/TestPigServerLocal.java
Date Tue, 21 May 2019 10:41:47 GMT
Author: nkollar
Date: Tue May 21 10:41:47 2019
New Revision: 1859620

URL: http://svn.apache.org/viewvc?rev=1859620&view=rev
Log:
PIG-5387: Test failures on JRE 11

Modified:
    pig/trunk/src/org/apache/pig/impl/plan/Operator.java
    pig/trunk/test/org/apache/pig/test/TestPigServer.java
    pig/trunk/test/org/apache/pig/test/TestPigServerLocal.java

Modified: pig/trunk/src/org/apache/pig/impl/plan/Operator.java
URL: http://svn.apache.org/viewvc/pig/trunk/src/org/apache/pig/impl/plan/Operator.java?rev=1859620&r1=1859619&r2=1859620&view=diff
==============================================================================
--- pig/trunk/src/org/apache/pig/impl/plan/Operator.java (original)
+++ pig/trunk/src/org/apache/pig/impl/plan/Operator.java Tue May 21 10:41:47 2019
@@ -18,12 +18,9 @@
 
 package org.apache.pig.impl.plan;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.io.Serializable;
-import java.lang.StringBuilder;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.pig.impl.plan.OperatorKey;
 
 /**
  * Base class for all types of operators.
@@ -152,7 +149,11 @@ abstract public class Operator<V extends
         return getProjectionMap();
     }
 
-    
+    // Added because on Java 11 while serializing the logical plan we hit JDK-8201131
+    private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException
{
+        in.defaultReadObject();
+    }
+
     /**
      * Make any necessary changes to a node based on a change of position in the
      * plan. This allows operators to rewire their projections, etc. when they

Modified: pig/trunk/test/org/apache/pig/test/TestPigServer.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServer.java?rev=1859620&r1=1859619&r2=1859620&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServer.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServer.java Tue May 21 10:41:47 2019
@@ -33,6 +33,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -141,11 +142,26 @@ public class TestPigServer {
     // dynamically add more resources to the system class loader
     private static void registerNewResource(String file) throws Exception {
         URL urlToAdd = new File(file).toURI().toURL();
-        URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
-        Method addMethod = URLClassLoader.class.
-                getDeclaredMethod("addURL", new Class[]{URL.class});
-        addMethod.setAccessible(true);
-        addMethod.invoke(sysLoader, new Object[]{urlToAdd});
+        ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
+        // Find the class loader below bootstrap class loader
+        // It is either the system class loader (first invocation), or the new URLClassLoader
added below
+        while (sysLoader.getParent().getParent() != null) {
+            sysLoader = sysLoader.getParent();
+        }
+        // Check if this class loader is instance of URLClassLoader
+        // On Java 8 and before it is, add resources via addURL method
+        // On Java 11 and after it isn't, add a new URLClassLoader with the new resources
above it
+        if (sysLoader instanceof URLClassLoader) {
+            Method addMethod = URLClassLoader.class.
+              getDeclaredMethod("addURL", new Class[]{URL.class});
+            addMethod.setAccessible(true);
+            addMethod.invoke(sysLoader, new Object[]{urlToAdd});
+        } else {
+            Field parent = ClassLoader.class.getDeclaredField("parent");
+            parent.setAccessible(true);
+            ClassLoader urlClassLoader = new URLClassLoader(new URL[]{urlToAdd}, ClassLoader.getSystemClassLoader().getParent());
+            parent.set(ClassLoader.getSystemClassLoader(), urlClassLoader);
+        }
     }
 
     /**

Modified: pig/trunk/test/org/apache/pig/test/TestPigServerLocal.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestPigServerLocal.java?rev=1859620&r1=1859619&r2=1859620&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestPigServerLocal.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestPigServerLocal.java Tue May 21 10:41:47 2019
@@ -29,6 +29,7 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.StringReader;
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
@@ -68,17 +69,6 @@ public class TestPigServerLocal {
     public void setUp() throws Exception{
         tempDir = Files.createTempDir();
         tempDir.deleteOnExit();
-        registerNewResource(tempDir.getAbsolutePath());
-    }
-
-    // dynamically add more resources to the system class loader
-    private static void registerNewResource(String file) throws Exception {
-        URL urlToAdd = new File(file).toURI().toURL();
-        URLClassLoader sysLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
-        Method addMethod = URLClassLoader.class.
-                getDeclaredMethod("addURL", new Class[]{URL.class});
-        addMethod.setAccessible(true);
-        addMethod.invoke(sysLoader, new Object[]{urlToAdd});
     }
 
     @Test



Mime
View raw message