8264148: Update spec for exceptions retrofitted for exception chaining
Reviewed-by: rriggs, smarks
This commit is contained in:
parent
353807c5f1
commit
815248ab27
@ -1193,7 +1193,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
try {
|
||||
writeObjectMethod.invoke(obj, new Object[]{ out });
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
if (th instanceof IOException) {
|
||||
throw (IOException) th;
|
||||
} else {
|
||||
@ -1223,7 +1223,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
try {
|
||||
readObjectMethod.invoke(obj, new Object[]{ in });
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
if (th instanceof ClassNotFoundException) {
|
||||
throw (ClassNotFoundException) th;
|
||||
} else if (th instanceof IOException) {
|
||||
@ -1254,7 +1254,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
try {
|
||||
readObjectNoDataMethod.invoke(obj, (Object[]) null);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
if (th instanceof ObjectStreamException) {
|
||||
throw (ObjectStreamException) th;
|
||||
} else {
|
||||
@ -1283,7 +1283,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
try {
|
||||
return writeReplaceMethod.invoke(obj, (Object[]) null);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
if (th instanceof ObjectStreamException) {
|
||||
throw (ObjectStreamException) th;
|
||||
} else {
|
||||
@ -1313,7 +1313,7 @@ public class ObjectStreamClass implements Serializable {
|
||||
try {
|
||||
return readResolveMethod.invoke(obj, (Object[]) null);
|
||||
} catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
if (th instanceof ObjectStreamException) {
|
||||
throw (ObjectStreamException) th;
|
||||
} else {
|
||||
|
@ -33,13 +33,6 @@ package java.io;
|
||||
* field. The stream is reset to it's initial state and all references
|
||||
* to objects already deserialized are discarded.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "exception causing
|
||||
* the abort" that is provided at construction time and
|
||||
* accessed via the public {@link #detail} field is now known as the
|
||||
* <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
|
||||
* method, as well as the aforementioned "legacy field."
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public class WriteAbortedException extends ObjectStreamException {
|
||||
@ -49,12 +42,13 @@ public class WriteAbortedException extends ObjectStreamException {
|
||||
/**
|
||||
* Exception that was caught while writing the ObjectStream.
|
||||
*
|
||||
* <p>This field predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
* @deprecated This field predates the general-purpose exception
|
||||
* chaining facility. The {@link Throwable#getCause()} method is
|
||||
* now the preferred means of obtaining this information.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
@Deprecated(since="17")
|
||||
public Exception detail;
|
||||
|
||||
/**
|
||||
@ -87,6 +81,7 @@ public class WriteAbortedException extends ObjectStreamException {
|
||||
* which may be null.
|
||||
* @since 1.4
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return detail;
|
||||
}
|
||||
|
@ -42,13 +42,6 @@ import java.io.ObjectStreamField;
|
||||
* <p>
|
||||
* but no definition for the class with the specified name could be found.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "optional exception
|
||||
* that was raised while loading the class" that may be provided at
|
||||
* construction time and accessed via the {@link #getException()} method is
|
||||
* now known as the <i>cause</i>, and may be accessed via the {@link
|
||||
* Throwable#getCause()} method, as well as the aforementioned "legacy method."
|
||||
*
|
||||
* @see java.lang.Class#forName(java.lang.String)
|
||||
* @see java.lang.ClassLoader#findSystemClass(java.lang.String)
|
||||
* @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
|
||||
@ -95,7 +88,8 @@ public class ClassNotFoundException extends ReflectiveOperationException {
|
||||
* Returns the exception that was raised if an error occurred while
|
||||
* attempting to load the class. Otherwise, returns {@code null}.
|
||||
*
|
||||
* <p>This method predates the general-purpose exception chaining facility.
|
||||
* @apiNote
|
||||
* This method predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
*
|
||||
|
@ -36,13 +36,6 @@ import java.io.ObjectStreamField;
|
||||
* exception occurred during evaluation of a static initializer or the
|
||||
* initializer for a static variable.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "saved throwable
|
||||
* object" that may be provided at construction time and accessed via
|
||||
* the {@link #getException()} method is now known as the <i>cause</i>,
|
||||
* and may be accessed via the {@link Throwable#getCause()} method, as well
|
||||
* as the aforementioned "legacy method."
|
||||
*
|
||||
* @author Frank Yellin
|
||||
* @since 1.1
|
||||
*/
|
||||
@ -92,7 +85,8 @@ public class ExceptionInInitializerError extends LinkageError {
|
||||
* Returns the exception that occurred during a static initialization that
|
||||
* caused this error to be created.
|
||||
*
|
||||
* <p>This method predates the general-purpose exception chaining facility.
|
||||
* @apiNote
|
||||
* This method predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
*
|
||||
|
@ -29,13 +29,6 @@ package java.lang.reflect;
|
||||
* InvocationTargetException is a checked exception that wraps
|
||||
* an exception thrown by an invoked method or constructor.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "target exception"
|
||||
* that is provided at construction time and accessed via the
|
||||
* {@link #getTargetException()} method is now known as the <i>cause</i>,
|
||||
* and may be accessed via the {@link Throwable#getCause()} method,
|
||||
* as well as the aforementioned "legacy method."
|
||||
*
|
||||
* @see Method
|
||||
* @see Constructor
|
||||
* @since 1.1
|
||||
@ -90,7 +83,8 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
||||
/**
|
||||
* Get the thrown target exception.
|
||||
*
|
||||
* <p>This method predates the general-purpose exception chaining facility.
|
||||
* @apiNote
|
||||
* This method predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
*
|
||||
@ -107,6 +101,7 @@ public class InvocationTargetException extends ReflectiveOperationException {
|
||||
* @return the cause of this exception.
|
||||
* @since 1.4
|
||||
*/
|
||||
@Override
|
||||
public Throwable getCause() {
|
||||
return target;
|
||||
}
|
||||
|
@ -48,15 +48,6 @@ import jdk.internal.access.SharedSecrets;
|
||||
* {@code RuntimeException}, so it is an unchecked exception
|
||||
* that wraps a checked exception.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to
|
||||
* conform to the general purpose exception-chaining mechanism. The
|
||||
* "undeclared checked exception that was thrown by the invocation
|
||||
* handler" that may be provided at construction time and accessed via
|
||||
* the {@link #getUndeclaredThrowable()} method is now known as the
|
||||
* <i>cause</i>, and may be accessed via the {@link
|
||||
* Throwable#getCause()} method, as well as the aforementioned "legacy
|
||||
* method."
|
||||
*
|
||||
* @author Peter Jones
|
||||
* @see InvocationHandler
|
||||
* @since 1.3
|
||||
@ -94,7 +85,8 @@ public class UndeclaredThrowableException extends RuntimeException {
|
||||
* Returns the {@code Throwable} instance wrapped in this
|
||||
* {@code UndeclaredThrowableException}, which may be {@code null}.
|
||||
*
|
||||
* <p>This method predates the general-purpose exception chaining facility.
|
||||
* @apiNote
|
||||
* This method predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
*
|
||||
|
@ -42,13 +42,6 @@ import jdk.internal.access.SharedSecrets;
|
||||
* {@code PrivilegedActionException} is a "wrapper"
|
||||
* for an exception thrown by a privileged action.
|
||||
*
|
||||
* <p>As of release 1.4, this exception has been retrofitted to conform to
|
||||
* the general purpose exception-chaining mechanism. The "exception thrown
|
||||
* by the privileged computation" that is provided at construction time and
|
||||
* accessed via the {@link #getException()} method is now known as the
|
||||
* <i>cause</i>, and may be accessed via the {@link Throwable#getCause()}
|
||||
* method, as well as the aforementioned "legacy method."
|
||||
*
|
||||
* @since 1.2
|
||||
* @see PrivilegedExceptionAction
|
||||
* @see AccessController#doPrivileged(PrivilegedExceptionAction)
|
||||
@ -73,7 +66,8 @@ public class PrivilegedActionException extends Exception {
|
||||
* Returns the exception thrown by the privileged computation that
|
||||
* resulted in this {@code PrivilegedActionException}.
|
||||
*
|
||||
* <p>This method predates the general-purpose exception chaining facility.
|
||||
* @apiNote
|
||||
* This method predates the general-purpose exception chaining facility.
|
||||
* The {@link Throwable#getCause()} method is now the preferred means of
|
||||
* obtaining this information.
|
||||
*
|
||||
|
@ -3195,7 +3195,7 @@ public abstract class ResourceBundle {
|
||||
} catch (InvocationTargetException e) {
|
||||
uncheckedThrow(e);
|
||||
} catch (PrivilegedActionException e) {
|
||||
assert e.getException() instanceof NoSuchMethodException;
|
||||
assert e.getCause() instanceof NoSuchMethodException;
|
||||
throw new InstantiationException("public no-arg constructor " +
|
||||
"does not exist in " + bundleClass.getName());
|
||||
}
|
||||
@ -3230,7 +3230,7 @@ public abstract class ResourceBundle {
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (IOException) e.getException();
|
||||
throw (IOException) e.getCause();
|
||||
}
|
||||
if (stream != null) {
|
||||
try {
|
||||
|
@ -765,7 +765,7 @@ public class PolicyFile extends java.security.Policy {
|
||||
}
|
||||
} catch (java.lang.reflect.InvocationTargetException ite) {
|
||||
Object[] source = {pe.permission,
|
||||
ite.getTargetException().toString()};
|
||||
ite.getCause().toString()};
|
||||
System.err.println(
|
||||
LocalizedMessage.getNonlocalized(
|
||||
POLICY + ".error.adding.Permission.perm.message",
|
||||
|
@ -127,7 +127,7 @@ public class CRLExtensions {
|
||||
throw new CRLException("Duplicate extensions not allowed");
|
||||
}
|
||||
} catch (InvocationTargetException invk) {
|
||||
throw new CRLException(invk.getTargetException().getMessage());
|
||||
throw new CRLException(invk.getCause().getMessage());
|
||||
} catch (Exception e) {
|
||||
throw new CRLException(e.toString());
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public class CertificateExtensions implements CertAttrSet<Extension> {
|
||||
throw new IOException("Duplicate extensions not allowed");
|
||||
}
|
||||
} catch (InvocationTargetException invk) {
|
||||
Throwable e = invk.getTargetException();
|
||||
Throwable e = invk.getCause();
|
||||
if (ext.isCritical() == false) {
|
||||
// ignore errors parsing non-critical extensions
|
||||
if (unparseableExtensions == null) {
|
||||
|
@ -326,7 +326,7 @@ final class ProcessImpl extends Process {
|
||||
return null;
|
||||
});
|
||||
} catch (PrivilegedActionException ex) {
|
||||
throw (IOException) ex.getException();
|
||||
throw (IOException) ex.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -485,7 +485,7 @@ public class EventHandler implements InvocationHandler {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
catch (InvocationTargetException ex) {
|
||||
Throwable th = ex.getTargetException();
|
||||
Throwable th = ex.getCause();
|
||||
throw (th instanceof RuntimeException)
|
||||
? (RuntimeException) th
|
||||
: new RuntimeException(th);
|
||||
|
@ -313,7 +313,7 @@ public class Statement {
|
||||
iae);
|
||||
}
|
||||
catch (InvocationTargetException ite) {
|
||||
Throwable te = ite.getTargetException();
|
||||
Throwable te = ite.getCause();
|
||||
if (te instanceof Exception) {
|
||||
throw (Exception)te;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ public class MBeanInstantiator {
|
||||
moi= cons.newInstance();
|
||||
} catch (InvocationTargetException e) {
|
||||
// Wrap the exception.
|
||||
Throwable t = e.getTargetException();
|
||||
Throwable t = e.getCause();
|
||||
if (t instanceof RuntimeException) {
|
||||
throw new RuntimeMBeanException((RuntimeException)t,
|
||||
"RuntimeException thrown in the MBean's empty constructor");
|
||||
@ -318,7 +318,7 @@ public class MBeanInstantiator {
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
// Wrap the exception.
|
||||
Throwable th = e.getTargetException();
|
||||
Throwable th = e.getCause();
|
||||
if (th instanceof RuntimeException) {
|
||||
throw new RuntimeMBeanException((RuntimeException)th,
|
||||
"RuntimeException thrown in the MBean's constructor");
|
||||
|
@ -1201,7 +1201,7 @@ public class RequiredModelMBean
|
||||
"RequiredModelMBean while trying to " +
|
||||
"invoke operation " + opName);
|
||||
} catch (InvocationTargetException ite) {
|
||||
Throwable mmbTargEx = ite.getTargetException();
|
||||
Throwable mmbTargEx = ite.getCause();
|
||||
if (mmbTargEx instanceof RuntimeException) {
|
||||
throw new MBeanException ((RuntimeException)mmbTargEx,
|
||||
"RuntimeException thrown in RequiredModelMBean "+
|
||||
|
@ -238,7 +238,7 @@ public final class Connection implements Runnable {
|
||||
outStream = new BufferedOutputStream(sock.getOutputStream());
|
||||
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable realException = e.getTargetException();
|
||||
Throwable realException = e.getCause();
|
||||
// realException.printStackTrace();
|
||||
|
||||
CommunicationException ce =
|
||||
|
@ -1485,7 +1485,7 @@ public class Activation implements Serializable {
|
||||
try {
|
||||
execPolicyMethod.invoke(execPolicy, desc, cmd);
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable targetException = e.getTargetException();
|
||||
Throwable targetException = e.getCause();
|
||||
if (targetException instanceof SecurityException) {
|
||||
throw (SecurityException) targetException;
|
||||
} else {
|
||||
|
@ -309,7 +309,7 @@ public class ActivationGroupImpl extends ActivationGroup {
|
||||
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new ActivationException("exception in object constructor",
|
||||
e.getTargetException());
|
||||
e.getCause());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new ActivationException("unable to activate object", e);
|
||||
|
@ -135,7 +135,7 @@ public class Main {
|
||||
System.exit(1);
|
||||
} catch (InvocationTargetException e) {
|
||||
// leave VM to handle the stacktrace, in the standard manner
|
||||
throw e.getTargetException();
|
||||
throw e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ public class Main {
|
||||
} catch (InvocationTargetException e) {
|
||||
// remove stack frames for source launcher
|
||||
int invocationFrames = e.getStackTrace().length;
|
||||
Throwable target = e.getTargetException();
|
||||
Throwable target = e.getCause();
|
||||
StackTraceElement[] targetTrace = target.getStackTrace();
|
||||
target.setStackTrace(Arrays.copyOfRange(targetTrace, 0, targetTrace.length - invocationFrames));
|
||||
throw e;
|
||||
|
@ -58,8 +58,8 @@ public class VMObjectFactory<T extends VMObject> {
|
||||
return c.newInstance(new Object[] { addr });
|
||||
}
|
||||
catch (java.lang.reflect.InvocationTargetException ite) {
|
||||
if (ite.getTargetException() instanceof RuntimeException) {
|
||||
throw (RuntimeException)ite.getTargetException();
|
||||
if (ite.getCause() instanceof RuntimeException) {
|
||||
throw (RuntimeException)ite.getCause();
|
||||
}
|
||||
throw new ConstructionException(ite);
|
||||
}
|
||||
|
@ -288,7 +288,7 @@ public class Utils {
|
||||
try {
|
||||
return c.newInstance(param);
|
||||
} catch (InvocationTargetException e) {
|
||||
Throwable t = e.getTargetException();
|
||||
Throwable t = e.getCause();
|
||||
if (t instanceof Exception) {
|
||||
throw (Exception) t;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user