From aa31bc6c313789c344d715b7c1aeea0cd8de47e2 Mon Sep 17 00:00:00 2001 From: Takuya UESHIN Date: Wed, 27 Jul 2016 14:00:46 +0900 Subject: [PATCH] LANG-1251: SerializationUtils.ClassLoaderAwareObjectInputStream should use static initializer to initialize primitiveTypes map (closes #180) Modify to use static initializer to initialize primitiveTypes map. --- .../commons/lang3/SerializationUtils.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java b/src/main/java/org/apache/commons/lang3/SerializationUtils.java index 68ebbd5b6..4ffc86558 100644 --- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java +++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java @@ -283,6 +283,19 @@ public class SerializationUtils { static class ClassLoaderAwareObjectInputStream extends ObjectInputStream { private static final Map> primitiveTypes = new HashMap>(); + + static { + primitiveTypes.put("byte", byte.class); + primitiveTypes.put("short", short.class); + primitiveTypes.put("int", int.class); + primitiveTypes.put("long", long.class); + primitiveTypes.put("float", float.class); + primitiveTypes.put("double", double.class); + primitiveTypes.put("boolean", boolean.class); + primitiveTypes.put("char", char.class); + primitiveTypes.put("void", void.class); + } + private final ClassLoader classLoader; /** @@ -295,16 +308,6 @@ public class SerializationUtils { public ClassLoaderAwareObjectInputStream(final InputStream in, final ClassLoader classLoader) throws IOException { super(in); this.classLoader = classLoader; - - primitiveTypes.put("byte", byte.class); - primitiveTypes.put("short", short.class); - primitiveTypes.put("int", int.class); - primitiveTypes.put("long", long.class); - primitiveTypes.put("float", float.class); - primitiveTypes.put("double", double.class); - primitiveTypes.put("boolean", boolean.class); - primitiveTypes.put("char", char.class); - primitiveTypes.put("void", void.class); } /**