blob: 5fd70c24a8795dbde7c230c71374188ff62919f2 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2005 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package java.security.cert;
27
28import java.security.GeneralSecurityException;
29
30/**
31 * An exception indicating one of a variety of problems encountered when
32 * validating a certification path.
33 * <p>
34 * A <code>CertPathValidatorException</code> provides support for wrapping
35 * exceptions. The {@link #getCause getCause} method returns the throwable,
36 * if any, that caused this exception to be thrown.
37 * <p>
38 * A <code>CertPathValidatorException</code> may also include the
39 * certification path that was being validated when the exception was thrown
40 * and the index of the certificate in the certification path that caused the
41 * exception to be thrown. Use the {@link #getCertPath getCertPath} and
42 * {@link #getIndex getIndex} methods to retrieve this information.
43 *
44 * <p>
45 * <b>Concurrent Access</b>
46 * <p>
47 * Unless otherwise specified, the methods defined in this class are not
48 * thread-safe. Multiple threads that need to access a single
49 * object concurrently should synchronize amongst themselves and
50 * provide the necessary locking. Multiple threads each manipulating
51 * separate objects need not synchronize.
52 *
53 * @see CertPathValidator
54 *
55 * @since 1.4
56 * @author Yassir Elley
57 */
58public class CertPathValidatorException extends GeneralSecurityException {
59
60 private static final long serialVersionUID = -3083180014971893139L;
61
62 /**
63 * @serial the index of the certificate in the certification path
64 * that caused the exception to be thrown
65 */
66 private int index = -1;
67
68 /**
69 * @serial the <code>CertPath</code> that was being validated when
70 * the exception was thrown
71 */
72 private CertPath certPath;
73
74 /**
75 * Creates a <code>CertPathValidatorException</code> with
76 * no detail message.
77 */
78 public CertPathValidatorException() {
79 super();
80 }
81
82 /**
83 * Creates a <code>CertPathValidatorException</code> with the given
84 * detail message. A detail message is a <code>String</code> that
85 * describes this particular exception.
86 *
87 * @param msg the detail message
88 */
89 public CertPathValidatorException(String msg) {
90 super(msg);
91 }
92
93 /**
94 * Creates a <code>CertPathValidatorException</code> that wraps the
95 * specified throwable. This allows any exception to be converted into a
96 * <code>CertPathValidatorException</code>, while retaining information
97 * about the wrapped exception, which may be useful for debugging. The
98 * detail message is set to (<code>cause==null ? null : cause.toString()
99 * </code>) (which typically contains the class and detail message of
100 * cause).
101 *
102 * @param cause the cause (which is saved for later retrieval by the
103 * {@link #getCause getCause()} method). (A <code>null</code> value is
104 * permitted, and indicates that the cause is nonexistent or unknown.)
105 */
106 public CertPathValidatorException(Throwable cause) {
107 super(cause);
108 }
109
110 /**
111 * Creates a <code>CertPathValidatorException</code> with the specified
112 * detail message and cause.
113 *
114 * @param msg the detail message
115 * @param cause the cause (which is saved for later retrieval by the
116 * {@link #getCause getCause()} method). (A <code>null</code> value is
117 * permitted, and indicates that the cause is nonexistent or unknown.)
118 */
119 public CertPathValidatorException(String msg, Throwable cause) {
120 super(msg, cause);
121 }
122
123 /**
124 * Creates a <code>CertPathValidatorException</code> with the specified
125 * detail message, cause, certification path, and index.
126 *
127 * @param msg the detail message (or <code>null</code> if none)
128 * @param cause the cause (or <code>null</code> if none)
129 * @param certPath the certification path that was in the process of
130 * being validated when the error was encountered
131 * @param index the index of the certificate in the certification path
132 * that caused the error (or -1 if not applicable). Note that
133 * the list of certificates in a <code>CertPath</code> is zero based.
134 * @throws IndexOutOfBoundsException if the index is out of range
135 * <code>(index < -1 || (certPath != null && index >=
136 * certPath.getCertificates().size())</code>
137 * @throws IllegalArgumentException if <code>certPath</code> is
138 * <code>null</code> and <code>index</code> is not -1
139 */
140 public CertPathValidatorException(String msg, Throwable cause,
141 CertPath certPath, int index) {
142 super(msg, cause);
143 if (certPath == null && index != -1) {
144 throw new IllegalArgumentException();
145 }
146 if (index < -1 ||
147 (certPath != null && index >= certPath.getCertificates().size())) {
148 throw new IndexOutOfBoundsException();
149 }
150 this.certPath = certPath;
151 this.index = index;
152 }
153
154 /**
155 * Returns the certification path that was being validated when
156 * the exception was thrown.
157 *
158 * @return the <code>CertPath</code> that was being validated when
159 * the exception was thrown (or <code>null</code> if not specified)
160 */
161 public CertPath getCertPath() {
162 return this.certPath;
163 }
164
165 /**
166 * Returns the index of the certificate in the certification path
167 * that caused the exception to be thrown. Note that the list of
168 * certificates in a <code>CertPath</code> is zero based. If no
169 * index has been set, -1 is returned.
170 *
171 * @return the index that has been set, or -1 if none has been set
172 */
173 public int getIndex() {
174 return this.index;
175 }
176
177}