1 /* 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.security; 27 28 // Android-changed: Stubbed the implementation. Android doesn't support SecurityManager. 29 // See comments in java.lang.SecurityManager for details. 30 /** 31 * Legacy security code; do not use. 32 * 33 * This exception is thrown by 34 * {@code doPrivileged(PrivilegedExceptionAction)} and 35 * {@code doPrivileged(PrivilegedExceptionAction, 36 * AccessControlContext context)} to indicate 37 * that the action being performed threw a checked exception. The exception 38 * thrown by the action can be obtained by calling the 39 * {@code getException} method. In effect, an 40 * {@code PrivilegedActionException} is a "wrapper" 41 * for an exception thrown by a privileged action. 42 * 43 * <p>As of release 1.4, this exception has been retrofitted to conform to 44 * the general purpose exception-chaining mechanism. The "exception thrown 45 * by the privileged computation" that is provided at construction time and 46 * accessed via the {@link #getException()} method is now known as the 47 * <i>cause</i>, and may be accessed via the {@link Throwable#getCause()} 48 * method, as well as the aforementioned "legacy method." 49 * 50 * @since 1.2 51 * @see PrivilegedExceptionAction 52 * @see AccessController#doPrivileged(PrivilegedExceptionAction) 53 * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext) 54 */ 55 public class PrivilegedActionException extends Exception { 56 // use serialVersionUID from JDK 1.2.2 for interoperability 57 private static final long serialVersionUID = 4724086851538908602L; 58 59 /** 60 * @serial 61 */ 62 private Exception exception; 63 64 /** 65 * Constructs a new PrivilegedActionException "wrapping" 66 * the specific Exception. 67 * 68 * @param exception The exception thrown 69 */ PrivilegedActionException(Exception exception)70 public PrivilegedActionException(Exception exception) { 71 super((Throwable)null); // Disallow initCause 72 this.exception = exception; 73 } 74 75 /** 76 * Returns the exception thrown by the privileged computation that 77 * resulted in this {@code PrivilegedActionException}. 78 * 79 * <p>This method predates the general-purpose exception chaining facility. 80 * The {@link Throwable#getCause()} method is now the preferred means of 81 * obtaining this information. 82 * 83 * @return the exception thrown by the privileged computation that 84 * resulted in this {@code PrivilegedActionException}. 85 * @see PrivilegedExceptionAction 86 * @see AccessController#doPrivileged(PrivilegedExceptionAction) 87 * @see AccessController#doPrivileged(PrivilegedExceptionAction, 88 * AccessControlContext) 89 */ getException()90 public Exception getException() { 91 return exception; 92 } 93 94 /** 95 * Returns the cause of this exception (the exception thrown by 96 * the privileged computation that resulted in this 97 * {@code PrivilegedActionException}). 98 * 99 * @return the cause of this exception. 100 * @since 1.4 101 */ getCause()102 public Throwable getCause() { 103 return exception; 104 } 105 toString()106 public String toString() { 107 String s = getClass().getName(); 108 return (exception != null) ? (s + ": " + exception.toString()) : s; 109 } 110 } 111