From 213c3ae379d1a4445def44f441590153f369dc61 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Mon, 18 Feb 2008 12:55:51 +0000 Subject: [PATCH] Apply patch for https://issues.apache.org/activemq/browse/AMQ-1584 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@628710 13f79535-47bb-0310-9956-ffa450edef68 --- .../ClassLoadingAwareObjectInputStream.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java b/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java index fac0f92e78..26549d3fc2 100644 --- a/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/ClassLoadingAwareObjectInputStream.java @@ -21,11 +21,13 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; import java.lang.reflect.Proxy; +import java.util.HashMap; public class ClassLoadingAwareObjectInputStream extends ObjectInputStream { private static final ClassLoader FALLBACK_CLASS_LOADER = ClassLoadingAwareObjectInputStream.class.getClassLoader(); - + /**

Maps primitive type names to corresponding class objects.

*/ + private static final HashMap primClasses = new HashMap(8, 1.0F); public ClassLoadingAwareObjectInputStream(InputStream in) throws IOException { super(in); } @@ -49,12 +51,32 @@ public class ClassLoadingAwareObjectInputStream extends ObjectInputStream { } } - private Class load(String className, ClassLoader cl) throws ClassNotFoundException { + private Class load(String className, ClassLoader cl) + throws ClassNotFoundException { try { return Class.forName(className, false, cl); } catch (ClassNotFoundException e) { - return Class.forName(className, false, FALLBACK_CLASS_LOADER); + final Class clazz = (Class) primClasses.get(className); + if (clazz != null) { + return clazz; + } else { + return Class.forName(className, false, FALLBACK_CLASS_LOADER); + } } } + + + + static { + primClasses.put("boolean", boolean.class); + primClasses.put("byte", byte.class); + primClasses.put("char", char.class); + primClasses.put("short", short.class); + primClasses.put("int", int.class); + primClasses.put("long", long.class); + primClasses.put("float", float.class); + primClasses.put("double", double.class); + primClasses.put("void", void.class); + } }