Remove duplicate static data in

SerializationUtils.ClassLoaderAwareObjectInputStream
This commit is contained in:
Gary Gregory 2024-06-03 08:00:42 -04:00
parent c0dc0cfbae
commit 45a955702a
3 changed files with 13 additions and 19 deletions

View File

@ -140,6 +140,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">StringUtils.stripAccents(String) doesn't handle T with stroke.</action>
<action issue="LANG-1735" type="fix" dev="ggregory" due-to="Tobias Kiecker">Fix Javadoc for FluentBitSet.setInclusive(int, int) #1222.</action>
<action type="fix" dev="ggregory" due-to="Tobias Kiecker">Same Javadoc changes as [TEXT-234] #1223.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Remove duplicate static data in SerializationUtils.ClassLoaderAwareObjectInputStream.</action>
<!-- UPDATE -->
<action type="update" dev="sebb" due-to="Dependabot, Gary Gregory">Bump commons-parent from 64 to 70 #1194.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.codehaus.mojo:exec-maven-plugin from 3.1.1 to 3.3.0 #1175, #1224.</action>

View File

@ -528,7 +528,7 @@ public class ClassUtils {
*/
public static Class<?> getClass(final ClassLoader classLoader, final String className, final boolean initialize) throws ClassNotFoundException {
try {
final Class<?> clazz = namePrimitiveMap.get(className);
final Class<?> clazz = getPrimitiveClass(className);
return clazz != null ? clazz : Class.forName(toCanonicalName(className), initialize, classLoader);
} catch (final ClassNotFoundException ex) {
// allow path separators (.) as inner class name separators
@ -750,6 +750,16 @@ public class ClassUtils {
return className.substring(0, i);
}
/**
* Gets the primitive class for the given class name, for example "byte".
*
* @param className the primitive class for the given class name.
* @return the primitive class.
*/
static Class<?> getPrimitiveClass(final String className) {
return namePrimitiveMap.get(className);
}
/**
* Returns the desired Method much like {@code Class.getMethod}, however it ensures that the returned Method is from a
* public class or interface and not from an anonymous inner class. This means that the Method is invokable and doesn't

View File

@ -25,8 +25,6 @@ import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
@ -61,21 +59,6 @@ public class SerializationUtils {
* class here is a workaround, see the JIRA issue LANG-626.</p>
*/
static final class ClassLoaderAwareObjectInputStream extends ObjectInputStream {
// Note: This is final to avoid Spotbugs CT_CONSTRUCTOR_THROW
private static final Map<String, Class<?>> primitiveTypes =
new HashMap<>();
static {
primitiveTypes.put(boolean.class.getSimpleName(), boolean.class);
primitiveTypes.put(byte.class.getSimpleName(), byte.class);
primitiveTypes.put(char.class.getSimpleName(), char.class);
primitiveTypes.put(double.class.getSimpleName(), double.class);
primitiveTypes.put(float.class.getSimpleName(), float.class);
primitiveTypes.put(int.class.getSimpleName(), int.class);
primitiveTypes.put(long.class.getSimpleName(), long.class);
primitiveTypes.put(short.class.getSimpleName(), short.class);
primitiveTypes.put(void.class.getSimpleName(), void.class);
}
private final ClassLoader classLoader;
@ -108,7 +91,7 @@ public class SerializationUtils {
try {
return Class.forName(name, false, Thread.currentThread().getContextClassLoader());
} catch (final ClassNotFoundException cnfe) {
final Class<?> cls = primitiveTypes.get(name);
final Class<?> cls = ClassUtils.getPrimitiveClass(name);
if (cls != null) {
return cls;
}