diff --git a/classpath/java/lang/Class.java b/classpath/java/lang/Class.java index eb183260d6..dcef601f12 100644 --- a/classpath/java/lang/Class.java +++ b/classpath/java/lang/Class.java @@ -37,7 +37,8 @@ import java.security.Permissions; import java.security.AllPermission; public final class Class implements Type, AnnotatedElement { - private static final int PrimitiveFlag = 1 << 5; + private static final int PrimitiveFlag = 1 << 5; + private static final int EnumFlag = 1 << 14; public final VMClass vmClass; @@ -555,6 +556,10 @@ public final class Class implements Type, AnnotatedElement { return (vmClass.vmFlags & PrimitiveFlag) != 0; } + public boolean isEnum() { + return getSuperclass() == Enum.class && (vmClass.flags & EnumFlag) != 0; + } + public URL getResource(String path) { if (! path.startsWith("/")) { String name = new String @@ -626,7 +631,7 @@ public final class Class implements Type, AnnotatedElement { for (VMClass c = vmClass; c != null; c = c.super_) { if (c.addendum != null && c.addendum.annotationTable != null) { Classes.link(c, c.loader); - + Object[] table = (Object[]) c.addendum.annotationTable; for (int i = 0; i < table.length; ++i) { Object[] a = (Object[]) table[i]; diff --git a/classpath/java/lang/Enum.java b/classpath/java/lang/Enum.java index 8d0d4756b0..a70b2074a9 100644 --- a/classpath/java/lang/Enum.java +++ b/classpath/java/lang/Enum.java @@ -30,7 +30,9 @@ public abstract class Enum> implements Comparable { } public static > T valueOf(Class 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> implements Comparable { } } } 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() {