Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / security / cert / CertPathValidatorException.java
blob9c7ad03c925231c361758900ff049eed935affdd
1 /* CertPathValidatorException.java -- wraps an exception during validation
2 of a CertPath
3 Copyright (C) 2002, 2005 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.security.cert;
42 import java.io.PrintStream;
43 import java.io.PrintWriter;
44 import java.security.GeneralSecurityException;
46 /**
47 * Indicates a problem while validating a certification path. In addition,
48 * it can store the path an index in that path that caused the problem. This
49 * class is not thread-safe.
51 * @author Eric Blake (ebb9@email.byu.edu)
52 * @see CertPathValidator
53 * @since 1.4
54 * @status updated to 1.4
56 public class CertPathValidatorException extends GeneralSecurityException
58 /**
59 * Compatible with JDK 1.4+.
61 private static final long serialVersionUID = -3083180014971893139L;
63 /**
64 * The index of the certificate path that failed, or -1.
66 * @serial the failed index
68 private final int index;
70 /**
71 * The <code>CertPath</code> that failed.
73 * @serial the object being validated at time of failure
75 private final CertPath certPath;
77 /**
78 * Create an exception without a message. The cause may be initialized. The
79 * index is set to -1 and the failed CertPath object to null.
81 public CertPathValidatorException()
83 this((String) null);
86 /**
87 * Create an exception with a message. The cause may be initialized. The
88 * index is set to -1 and the failed CertPath object to null.
90 * @param msg a message to display with exception
92 public CertPathValidatorException(String msg)
94 super(msg);
95 index = -1;
96 certPath = null;
99 /**
100 * Create an exception with a cause. The message will be
101 * <code>cause == null ? null : cause.toString()</code>. The index is set
102 * to -1 and the failed CertPath object to null.
104 * @param cause the cause
106 public CertPathValidatorException(Throwable cause)
108 this(cause == null ? null : cause.toString(), cause, null, -1);
112 * Create an exception with a cause and a message. The index is set to -1
113 * and the failed CertPath object to null.
115 * @param msg the message
116 * @param cause the cause
118 public CertPathValidatorException(String msg, Throwable cause)
120 this(msg, cause, null, -1);
124 * Create an exception with a cause, message, failed object, and index of
125 * failure in that CertPath.
127 * @param msg the message
128 * @param cause the cause
129 * @param certPath the path that was being validated, or null
130 * @param index the index of the path, or -1
131 * @throws IndexOutOfBoundsException if index is &lt; -1 or
132 * &gt; certPath.getCertificates().size()
133 * @throws IllegalArgumentException if certPath is null but index != -1
135 public CertPathValidatorException(String msg, Throwable cause,
136 CertPath certPath, int index)
138 super(msg);
139 initCause(cause);
140 if (index < -1 || (certPath != null
141 && index >= certPath.getCertificates().size()))
142 throw new IndexOutOfBoundsException();
143 if ((certPath == null) != (index == -1))
144 throw new IllegalArgumentException();
145 this.certPath = certPath;
146 this.index = index;
150 * Get the detail message.
152 * @return the detail message
154 public String getMessage()
156 return super.getMessage();
160 * Get the certificate path that had the failure, or null.
162 * @return the culprit path
164 public CertPath getCertPath()
166 return certPath;
170 * Get the index that failed, or -1.
172 * @return the colprit index
174 public int getIndex()
176 return index;
180 * Get the cause, null if unknown.
182 * @return the cause
184 public Throwable getCause()
186 return super.getCause();
190 * Convert this to a string, including its cause.
192 * @return the string conversion
194 public String toString()
196 return super.toString();
200 * Print the stack trace to <code>System.err</code>.
202 public void printStackTrace()
204 super.printStackTrace();
208 * Print the stack trace to a stream.
210 * @param stream the stream
212 public void printStackTrace(PrintStream stream)
214 super.printStackTrace(stream);
218 * Print the stack trace to a stream.
220 * @param stream the stream
222 public void printStackTrace(PrintWriter stream)
224 super.printStackTrace(stream);