Code review request for 6857789: (reflect) Create common superclass of reflective exceptions (original) (raw)

Joseph D. Darcy Joe.Darcy at Sun.COM
Thu Jul 9 22:47:24 UTC 2009


Hello.

Please review the patch below to fix

6857789:  (reflect) Create common superclass of reflective exceptions

Half a dozen checked exceptions thrown by methods in core reflection don't have a superclass more specific than Exception, requiring multiple catch blocks around code using core reflection operations. The fix is to change the direct superclass of the checked exceptions in question to a new shared checked exception, java.lang.ReflectiveOperationException.
This is useful whether or not multi-catch is added as a language change in JDK 7.

Inserting a new level into the superclass hierarchy is a binary compatible change (JLSv3 Chapter 13); the change should be transparent other than to reflective operations that specifically queried the superclass. All the exception classes in question already have explicit serialVersionUID fields so changing the superclass will be compatible from a serialization perspective too.

(A ccc request for this change is in progress too.)

Thanks,

-Joe

--- old/src/share/classes/java/lang/ClassNotFoundException.java
2009-07-09 14:38:05.000000000 -0700 +++ new/src/share/classes/java/lang/ClassNotFoundException.java
2009-07-09 14:38:05.000000000 -0700 @@ -50,7 +50,7 @@ * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) * @since JDK1.0 / -public class ClassNotFoundException extends Exception { +public class ClassNotFoundException extends ReflectiveOperationException { /* * use serialVersionUID from JDK 1.1.X for interoperability / --- old/src/share/classes/java/lang/IllegalAccessException.java
2009-07-09 14:38:06.000000000 -0700 +++ new/src/share/classes/java/lang/IllegalAccessException.java
2009-07-09 14:38:06.000000000 -0700 @@ -56,7 +56,7 @@ * @see java.lang.reflect.Constructor#newInstance(Object[]) * @since JDK1.0 / -public class IllegalAccessException extends Exception { +public class IllegalAccessException extends ReflectiveOperationException { private static final long serialVersionUID = 6616958222490762034L; /
--- old/src/share/classes/java/lang/InstantiationException.java
2009-07-09 14:38:06.000000000 -0700 +++ new/src/share/classes/java/lang/InstantiationException.java
2009-07-09 14:38:06.000000000 -0700 @@ -43,7 +43,7 @@ * @since JDK1.0 / public -class InstantiationException extends Exception { +class InstantiationException extends ReflectiveOperationException { private static final long serialVersionUID = -8441929162975509110L; /* --- old/src/share/classes/java/lang/NoSuchFieldException.java
2009-07-09 14:38:07.000000000 -0700 +++ new/src/share/classes/java/lang/NoSuchFieldException.java
2009-07-09 14:38:07.000000000 -0700 @@ -31,7 +31,7 @@ * @author unascribed * @since JDK1.1 / -public class NoSuchFieldException extends Exception { +public class NoSuchFieldException extends ReflectiveOperationException { private static final long serialVersionUID = -6143714805279938260L; /* --- old/src/share/classes/java/lang/NoSuchMethodException.java
2009-07-09 14:38:08.000000000 -0700 +++ new/src/share/classes/java/lang/NoSuchMethodException.java
2009-07-09 14:38:07.000000000 -0700 @@ -32,7 +32,7 @@ * @since JDK1.0 / public -class NoSuchMethodException extends Exception { +class NoSuchMethodException extends ReflectiveOperationException { private static final long serialVersionUID = 5034388446362600923L; /*

old/src/share/classes/java/lang/reflect/InvocationTargetException.java
2009-07-09 14:38:08.000000000 -0700 +++ new/src/share/classes/java/lang/reflect/InvocationTargetException.java
2009-07-09 14:38:08.000000000 -0700 @@ -39,7 +39,7 @@

saved for

retrieval

+}



More information about the core-libs-dev mailing list