< prev index next >

src/java.base/share/classes/java/lang/reflect/UndeclaredThrowableException.java

Print this page

        

*** 23,32 **** --- 23,39 ---- * questions. */ package java.lang.reflect; + import jdk.internal.misc.SharedSecrets; + + import java.io.IOException; + import java.io.ObjectInputStream; + import java.io.ObjectOutputStream; + import java.io.ObjectStreamField; + /** * Thrown by a method invocation on a proxy instance if its invocation * handler's {@link InvocationHandler#invoke invoke} method throws a * checked exception (a {@code Throwable} that is not assignable * to {@code RuntimeException} or {@code Error}) that
*** 57,81 **** */ public class UndeclaredThrowableException extends RuntimeException { static final long serialVersionUID = 330127114055056639L; /** - * the undeclared checked exception that was thrown - * @serial - */ - private Throwable undeclaredThrowable; - - /** * Constructs an {@code UndeclaredThrowableException} with the * specified {@code Throwable}. * * @param undeclaredThrowable the undeclared checked exception * that was thrown */ public UndeclaredThrowableException(Throwable undeclaredThrowable) { ! super((Throwable) null); // Disallow initCause ! this.undeclaredThrowable = undeclaredThrowable; } /** * Constructs an {@code UndeclaredThrowableException} with the * specified {@code Throwable} and a detail message. --- 64,81 ---- */ public class UndeclaredThrowableException extends RuntimeException { static final long serialVersionUID = 330127114055056639L; /** * Constructs an {@code UndeclaredThrowableException} with the * specified {@code Throwable}. * * @param undeclaredThrowable the undeclared checked exception * that was thrown */ public UndeclaredThrowableException(Throwable undeclaredThrowable) { ! super(null, undeclaredThrowable); // Disallow initCause } /** * Constructs an {@code UndeclaredThrowableException} with the * specified {@code Throwable} and a detail message.
*** 85,96 **** * @param s the detail message */ public UndeclaredThrowableException(Throwable undeclaredThrowable, String s) { ! super(s, null); // Disallow initCause ! this.undeclaredThrowable = undeclaredThrowable; } /** * Returns the {@code Throwable} instance wrapped in this * {@code UndeclaredThrowableException}, which may be {@code null}. --- 85,95 ---- * @param s the detail message */ public UndeclaredThrowableException(Throwable undeclaredThrowable, String s) { ! super(s, undeclaredThrowable); // Disallow initCause } /** * Returns the {@code Throwable} instance wrapped in this * {@code UndeclaredThrowableException}, which may be {@code null}.
*** 100,119 **** * obtaining this information. * * @return the undeclared checked exception that was thrown */ public Throwable getUndeclaredThrowable() { ! return undeclaredThrowable; } /** ! * Returns the cause of this exception (the {@code Throwable} ! * instance wrapped in this {@code UndeclaredThrowableException}, ! * which may be {@code null}). * ! * @return the cause of this exception. ! * @since 1.4 */ ! public Throwable getCause() { ! return undeclaredThrowable; } } --- 99,138 ---- * obtaining this information. * * @return the undeclared checked exception that was thrown */ public Throwable getUndeclaredThrowable() { ! return super.getCause(); } /** ! * Serializable fields for UndeclaredThrowableException. * ! * @serialField undeclaredThrowable Throwable */ ! private static final ObjectStreamField[] serialPersistentFields = { ! new ObjectStreamField("undeclaredThrowable", Throwable.class) ! }; ! ! /* ! * Reconstitutes the UndeclaredThrowableException instance from a stream ! * and initialize the cause properly when deserializing from an older ! * version. ! */ ! private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { ! ObjectInputStream.GetField fields = s.readFields(); ! Throwable exception = (Throwable) fields.get("undeclaredThrowable", null); ! if (exception != null) { ! SharedSecrets.getJavaLangAccess().setCause(this, exception); ! } ! } ! ! /* ! * To maintain compatibility with older implementation, write a serial ! * "ex" field with the cause as the value. ! */ ! private void writeObject(ObjectOutputStream out) throws IOException { ! ObjectOutputStream.PutField fields = out.putFields(); ! fields.put("undeclaredThrowable", super.getCause()); ! out.writeFields(); } }
< prev index next >