mirror of
https://github.com/corda/corda.git
synced 2025-06-13 04:38:19 +00:00
Add Class#isEnum and improve error handling in Enum.valueOf
This commit is contained in:
@ -30,7 +30,9 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
|
||||
}
|
||||
|
||||
public static <T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
|
||||
if (name == null) throw new NullPointerException();
|
||||
if (name == null) throw new NullPointerException("name");
|
||||
if (!enumType.isEnum())
|
||||
throw new IllegalArgumentException(enumType.getCanonicalName() + " is not an enum.");
|
||||
|
||||
try {
|
||||
Method method = enumType.getMethod("values");
|
||||
@ -41,10 +43,11 @@ public abstract class Enum<E extends Enum<E>> implements Comparable<E> {
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
// Cannot happen
|
||||
throw new Error(ex);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(name);
|
||||
throw new IllegalArgumentException(enumType.getCanonicalName() + "." + name + " is not an enum constant.");
|
||||
}
|
||||
|
||||
public int ordinal() {
|
||||
|
Reference in New Issue
Block a user