< prev index next >

src/java.base/share/classes/java/security/PrivilegedActionException.java

Print this page

        

*** 23,32 **** --- 23,39 ---- * questions. */ package java.security; + import jdk.internal.misc.SharedSecrets; + + import java.io.IOException; + import java.io.ObjectInputStream; + import java.io.ObjectOutputStream; + import java.io.ObjectStreamField; + /** * This exception is thrown by * {@code doPrivileged(PrivilegedExceptionAction)} and * {@code doPrivileged(PrivilegedExceptionAction, * AccessControlContext context)} to indicate
*** 51,79 **** public class PrivilegedActionException extends Exception { // use serialVersionUID from JDK 1.2.2 for interoperability private static final long serialVersionUID = 4724086851538908602L; /** - * @serial - */ - private Exception exception; - - /** * Constructs a new PrivilegedActionException &quot;wrapping&quot; * the specific Exception. * * @param exception The exception thrown */ public PrivilegedActionException(Exception exception) { ! super((Throwable)null); // Disallow initCause ! this.exception = 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. * The {@link Throwable#getCause()} method is now the preferred means of * obtaining this information. * * @return the exception thrown by the privileged computation that --- 58,80 ---- public class PrivilegedActionException extends Exception { // use serialVersionUID from JDK 1.2.2 for interoperability private static final long serialVersionUID = 4724086851538908602L; /** * Constructs a new PrivilegedActionException &quot;wrapping&quot; * the specific Exception. * * @param exception The exception thrown */ public PrivilegedActionException(Exception exception) { ! super(null, exception); // Disallow initCause } /** * Returns the exception thrown by the privileged computation that * resulted in this {@code PrivilegedActionException}. ! *Memory * <p>This method predates the general-purpose exception chaining facility. * The {@link Throwable#getCause()} method is now the preferred means of * obtaining this information. * * @return the exception thrown by the privileged computation that
*** 82,106 **** * @see AccessController#doPrivileged(PrivilegedExceptionAction) * @see AccessController#doPrivileged(PrivilegedExceptionAction, * AccessControlContext) */ public Exception getException() { ! return exception; } /** ! * Returns the cause of this exception (the exception thrown by ! * the privileged computation that resulted in this ! * {@code PrivilegedActionException}). * ! * @return the cause of this exception. ! * @since 1.4 */ ! public Throwable getCause() { ! return exception; } ! public String toString() { ! String s = getClass().getName(); ! return (exception != null) ? (s + ": " + exception.toString()) : s; } } --- 83,132 ---- * @see AccessController#doPrivileged(PrivilegedExceptionAction) * @see AccessController#doPrivileged(PrivilegedExceptionAction, * AccessControlContext) */ public Exception getException() { ! return (Exception)getCause(); ! } ! ! public String toString() { ! String s = getClass().getName(); ! return (getCause() != null) ? (s + ": " + getCause().toString()) : s; } + /** ! * Serializable fields for UndeclaredThrowableException. * ! * @serialField undeclaredThrowable Throwable */ ! private static final ObjectStreamField[] serialPersistentFields = { ! new ObjectStreamField("exception", Exception.class) ! }; ! ! /* ! * Reconstitutes the PrivilegedActionException instance from a stream ! * and initialize the cause properly when deserializing from an older ! * version. ! * ! * The getException and getCause method returns the private "exception" ! * field in the older implementation and PrivilegedActionException::cause ! * was set to null. ! */ ! private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { ! ObjectInputStream.GetField fields = s.readFields(); ! Exception exception = (Exception) fields.get("exception", null); ! if (exception != null) { ! SharedSecrets.getJavaLangAccess().setCause(this, exception); ! } } ! /* ! * To maintain compatibility with older implementation, write a serial ! * "exception" field with the cause as the value. ! */ ! private void writeObject(ObjectOutputStream out) throws IOException { ! ObjectOutputStream.PutField fields = out.putFields(); ! fields.put("exception", getException()); ! out.writeFields(); } }
< prev index next >