From ccecdf216fd1f113fbd76734eed8a452cfde5dff Mon Sep 17 00:00:00 2001 From: glen3b Date: Wed, 14 May 2014 16:06:26 -0700 Subject: [PATCH] Throw ClassNotFoundException when appropriate Currently, the ClassSource returned by ClassSource.fromMap will return null if the Class cannot be found (as that is the behavior of maps). However, other ClassSources throw a ClassNotFoundException if the class cannot be loaded. This commit changes the behavior of ClassSource.fromMap to throw a ClassNotFoundException if the class was not found in the map (or was mapped to null). This commit also changes the method to interpret a null map as an empty map. --- .../java/com/comphenix/protocol/utility/ClassSource.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ClassSource.java b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ClassSource.java index f2277c77..5832fa5e 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ClassSource.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/utility/ClassSource.java @@ -47,7 +47,12 @@ public abstract class ClassSource { return new ClassSource() { @Override public Class loadClass(String canonicalName) throws ClassNotFoundException { - return map.get(canonicalName); + Class loaded = map == null ? null : map.get(canonicalName); + if(loaded == null){ + // Throw the appropriate exception if we can't load the class + throw new ClassNotFoundException("The specified class could not be found by this ClassLoader."); + } + return loaded; } }; }