diff --git a/common/src/java/org/apache/hadoop/hive/common/JavaUtils.java b/common/src/java/org/apache/hadoop/hive/common/JavaUtils.java index 7d3980f..12e1e84 100644 --- a/common/src/java/org/apache/hadoop/hive/common/JavaUtils.java +++ b/common/src/java/org/apache/hadoop/hive/common/JavaUtils.java @@ -18,16 +18,18 @@ package org.apache.hadoop.hive.common; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - +import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; +import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URLClassLoader; import java.util.Arrays; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * Collection of Java class loading/reflection related utilities common across * Hive. @@ -98,8 +100,17 @@ public static void closeClassLoader(ClassLoader loader) throws IOException { if (loader instanceof Closeable) { ((Closeable)loader).close(); } else if (SUN_MISC_UTIL_RELEASE != null && loader instanceof URLClassLoader) { + PrintStream outputStream = System.out; + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + PrintStream newOutputStream = new PrintStream(byteArrayOutputStream); try { + // SUN_MISC_UTIL_RELEASE.invoke prints to System.out + // So we're changing the outputstream for that call, + // and setting it back to original System.out when we're done + System.setOut(newOutputStream); SUN_MISC_UTIL_RELEASE.invoke(null, loader); + String output = byteArrayOutputStream.toString("UTF8"); + LOG.debug(output); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof IOException) { throw (IOException)e.getTargetException(); @@ -108,6 +119,10 @@ public static void closeClassLoader(ClassLoader loader) throws IOException { } catch (Exception e) { throw new IOException(e); } + finally { + System.setOut(outputStream); + newOutputStream.close(); + } } }