You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@storm.apache.org by sr...@apache.org on 2015/12/08 19:09:58 UTC

[12/20] storm git commit: [StormSQL] Allow deserializing Java class with custom classloaders in tests.

[StormSQL] Allow deserializing Java class with custom classloaders in tests.


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/4d8cc419
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/4d8cc419
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/4d8cc419

Branch: refs/heads/master
Commit: 4d8cc419b109a11e1a1f6489aca8b8b528e77ab5
Parents: 3940007
Author: Haohui Mai <wh...@apache.org>
Authored: Wed Nov 11 10:03:07 2015 -0800
Committer: Haohui Mai <wh...@apache.org>
Committed: Fri Dec 4 11:09:27 2015 -0800

----------------------------------------------------------------------
 storm-core/src/jvm/backtype/storm/utils/Utils.java | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/4d8cc419/storm-core/src/jvm/backtype/storm/utils/Utils.java
----------------------------------------------------------------------
diff --git a/storm-core/src/jvm/backtype/storm/utils/Utils.java b/storm-core/src/jvm/backtype/storm/utils/Utils.java
index e0bbb1f..19fe5f1 100644
--- a/storm-core/src/jvm/backtype/storm/utils/Utils.java
+++ b/storm-core/src/jvm/backtype/storm/utils/Utils.java
@@ -38,8 +38,10 @@ import backtype.storm.serialization.DefaultSerializationDelegate;
 import backtype.storm.serialization.SerializationDelegate;
 import clojure.lang.IFn;
 import clojure.lang.RT;
+import com.google.common.annotations.VisibleForTesting;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.io.input.ClassLoaderObjectInputStream;
 import org.apache.commons.lang.StringUtils;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
@@ -118,6 +120,7 @@ public class Utils {
     private static ThreadLocal<TDeserializer> threadDes = new ThreadLocal<TDeserializer>();
 
     private static SerializationDelegate serializationDelegate;
+    private static ClassLoader cl = ClassLoader.getSystemClassLoader();
 
     static {
         Map conf = readStormConfig();
@@ -167,7 +170,7 @@ public class Utils {
     public static <T> T javaDeserialize(byte[] serialized, Class<T> clazz) {
         try {
             ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
-            ObjectInputStream ois = new ObjectInputStream(bis);
+            ObjectInputStream ois = new ClassLoaderObjectInputStream(cl, bis);
             Object ret = ois.readObject();
             ois.close();
             return (T)ret;
@@ -1293,5 +1296,15 @@ public class Utils {
             return defaultValue;
         }
     }
+
+    @VisibleForTesting
+    public static void setClassLoaderForJavaDeSerialize(ClassLoader cl) {
+        Utils.cl = cl;
+    }
+
+    @VisibleForTesting
+    public static void resetClassLoaderForJavaDeSerialize() {
+        Utils.cl = ClassLoader.getSystemClassLoader();
+    }
 }