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.
This commit is contained in:
glen3b 2014-05-14 16:06:26 -07:00
parent 818ac5cbde
commit ccecdf216f

View File

@ -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;
}
};
}