Archiviert
13
0

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.
Dieser Commit ist enthalten in:
glen3b 2014-05-14 16:06:26 -07:00
Ursprung 818ac5cbde
Commit ccecdf216f

Datei anzeigen

@ -47,7 +47,12 @@ public abstract class ClassSource {
return new ClassSource() { return new ClassSource() {
@Override @Override
public Class<?> loadClass(String canonicalName) throws ClassNotFoundException { 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;
} }
}; };
} }