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); + } }