• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @see PrivilegedExceptionAction
51  * @see AccessController#doPrivileged(PrivilegedExceptionAction)
52  * @see AccessController#doPrivileged(PrivilegedExceptionAction,AccessControlContext)
53  */
54 public class PrivilegedActionException extends Exception {
55     // use serialVersionUID from JDK 1.2.2 for interoperability
56     private static final long serialVersionUID = 4724086851538908602L;
57 
58     /**
59      * @serial
60      */
61     private Exception exception;
62 
63     /**
64      * Constructs a new PrivilegedActionException &quot;wrapping&quot;
65      * the specific Exception.
66      *
67      * @param exception The exception thrown
68      */
PrivilegedActionException(Exception exception)69     public PrivilegedActionException(Exception exception) {
70         super((Throwable)null);  // Disallow initCause
71         this.exception = exception;
72     }
73 
74     /**
75      * Returns the exception thrown by the privileged computation that
76      * resulted in this {@code PrivilegedActionException}.
77      *
78      * <p>This method predates the general-purpose exception chaining facility.
79      * The {@link Throwable#getCause()} method is now the preferred means of
80      * obtaining this information.
81      *
82      * @return the exception thrown by the privileged computation that
83      *         resulted in this {@code PrivilegedActionException}.
84      * @see PrivilegedExceptionAction
85      * @see AccessController#doPrivileged(PrivilegedExceptionAction)
86      * @see AccessController#doPrivileged(PrivilegedExceptionAction,
87      *                                            AccessControlContext)
88      */
getException()89     public Exception getException() {
90         return exception;
91     }
92 
93     /**
94      * Returns the cause of this exception (the exception thrown by
95      * the privileged computation that resulted in this
96      * {@code PrivilegedActionException}).
97      *
98      * @return  the cause of this exception.
99      * @since   1.4
100      */
getCause()101     public Throwable getCause() {
102         return exception;
103     }
104 
toString()105     public String toString() {
106         String s = getClass().getName();
107         return (exception != null) ? (s + ": " + exception.toString()) : s;
108     }
109 }
110