jdk/src/share/classes/java/security/cert/CertPathValidatorException.java
changeset 18551 882a3948c6e6
parent 18156 edb590d448c5
equal deleted inserted replaced
18550:6d0f51c99930 18551:882a3948c6e6
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    32 
    32 
    33 /**
    33 /**
    34  * An exception indicating one of a variety of problems encountered when
    34  * An exception indicating one of a variety of problems encountered when
    35  * validating a certification path.
    35  * validating a certification path.
    36  * <p>
    36  * <p>
    37  * A <code>CertPathValidatorException</code> provides support for wrapping
    37  * A {@code CertPathValidatorException} provides support for wrapping
    38  * exceptions. The {@link #getCause getCause} method returns the throwable,
    38  * exceptions. The {@link #getCause getCause} method returns the throwable,
    39  * if any, that caused this exception to be thrown.
    39  * if any, that caused this exception to be thrown.
    40  * <p>
    40  * <p>
    41  * A <code>CertPathValidatorException</code> may also include the
    41  * A {@code CertPathValidatorException} may also include the
    42  * certification path that was being validated when the exception was thrown,
    42  * certification path that was being validated when the exception was thrown,
    43  * the index of the certificate in the certification path that caused the
    43  * the index of the certificate in the certification path that caused the
    44  * exception to be thrown, and the reason that caused the failure. Use the
    44  * exception to be thrown, and the reason that caused the failure. Use the
    45  * {@link #getCertPath getCertPath}, {@link #getIndex getIndex}, and
    45  * {@link #getCertPath getCertPath}, {@link #getIndex getIndex}, and
    46  * {@link #getReason getReason} methods to retrieve this information.
    46  * {@link #getReason getReason} methods to retrieve this information.
    68      * that caused the exception to be thrown
    68      * that caused the exception to be thrown
    69      */
    69      */
    70     private int index = -1;
    70     private int index = -1;
    71 
    71 
    72     /**
    72     /**
    73      * @serial the <code>CertPath</code> that was being validated when
    73      * @serial the {@code CertPath} that was being validated when
    74      * the exception was thrown
    74      * the exception was thrown
    75      */
    75      */
    76     private CertPath certPath;
    76     private CertPath certPath;
    77 
    77 
    78     /**
    78     /**
    79      * @serial the reason the validation failed
    79      * @serial the reason the validation failed
    80      */
    80      */
    81     private Reason reason = BasicReason.UNSPECIFIED;
    81     private Reason reason = BasicReason.UNSPECIFIED;
    82 
    82 
    83     /**
    83     /**
    84      * Creates a <code>CertPathValidatorException</code> with
    84      * Creates a {@code CertPathValidatorException} with
    85      * no detail message.
    85      * no detail message.
    86      */
    86      */
    87     public CertPathValidatorException() {
    87     public CertPathValidatorException() {
    88         this(null, null);
    88         this(null, null);
    89     }
    89     }
    90 
    90 
    91     /**
    91     /**
    92      * Creates a <code>CertPathValidatorException</code> with the given
    92      * Creates a {@code CertPathValidatorException} with the given
    93      * detail message. A detail message is a <code>String</code> that
    93      * detail message. A detail message is a {@code String} that
    94      * describes this particular exception.
    94      * describes this particular exception.
    95      *
    95      *
    96      * @param msg the detail message
    96      * @param msg the detail message
    97      */
    97      */
    98     public CertPathValidatorException(String msg) {
    98     public CertPathValidatorException(String msg) {
    99         this(msg, null);
    99         this(msg, null);
   100     }
   100     }
   101 
   101 
   102     /**
   102     /**
   103      * Creates a <code>CertPathValidatorException</code> that wraps the
   103      * Creates a {@code CertPathValidatorException} that wraps the
   104      * specified throwable. This allows any exception to be converted into a
   104      * specified throwable. This allows any exception to be converted into a
   105      * <code>CertPathValidatorException</code>, while retaining information
   105      * {@code CertPathValidatorException}, while retaining information
   106      * about the wrapped exception, which may be useful for debugging. The
   106      * about the wrapped exception, which may be useful for debugging. The
   107      * detail message is set to (<code>cause==null ? null : cause.toString()
   107      * detail message is set to ({@code cause==null ? null : cause.toString()})
   108      * </code>) (which typically contains the class and detail message of
   108      * (which typically contains the class and detail message of
   109      * cause).
   109      * cause).
   110      *
   110      *
   111      * @param cause the cause (which is saved for later retrieval by the
   111      * @param cause the cause (which is saved for later retrieval by the
   112      * {@link #getCause getCause()} method). (A <code>null</code> value is
   112      * {@link #getCause getCause()} method). (A {@code null} value is
   113      * permitted, and indicates that the cause is nonexistent or unknown.)
   113      * permitted, and indicates that the cause is nonexistent or unknown.)
   114      */
   114      */
   115     public CertPathValidatorException(Throwable cause) {
   115     public CertPathValidatorException(Throwable cause) {
   116         this((cause == null ? null : cause.toString()), cause);
   116         this((cause == null ? null : cause.toString()), cause);
   117     }
   117     }
   118 
   118 
   119     /**
   119     /**
   120      * Creates a <code>CertPathValidatorException</code> with the specified
   120      * Creates a {@code CertPathValidatorException} with the specified
   121      * detail message and cause.
   121      * detail message and cause.
   122      *
   122      *
   123      * @param msg the detail message
   123      * @param msg the detail message
   124      * @param cause the cause (which is saved for later retrieval by the
   124      * @param cause the cause (which is saved for later retrieval by the
   125      * {@link #getCause getCause()} method). (A <code>null</code> value is
   125      * {@link #getCause getCause()} method). (A {@code null} value is
   126      * permitted, and indicates that the cause is nonexistent or unknown.)
   126      * permitted, and indicates that the cause is nonexistent or unknown.)
   127      */
   127      */
   128     public CertPathValidatorException(String msg, Throwable cause) {
   128     public CertPathValidatorException(String msg, Throwable cause) {
   129         this(msg, cause, null, -1);
   129         this(msg, cause, null, -1);
   130     }
   130     }
   131 
   131 
   132     /**
   132     /**
   133      * Creates a <code>CertPathValidatorException</code> with the specified
   133      * Creates a {@code CertPathValidatorException} with the specified
   134      * detail message, cause, certification path, and index.
   134      * detail message, cause, certification path, and index.
   135      *
   135      *
   136      * @param msg the detail message (or <code>null</code> if none)
   136      * @param msg the detail message (or {@code null} if none)
   137      * @param cause the cause (or <code>null</code> if none)
   137      * @param cause the cause (or {@code null} if none)
   138      * @param certPath the certification path that was in the process of
   138      * @param certPath the certification path that was in the process of
   139      * being validated when the error was encountered
   139      * being validated when the error was encountered
   140      * @param index the index of the certificate in the certification path
   140      * @param index the index of the certificate in the certification path
   141      * that caused the error (or -1 if not applicable). Note that
   141      * that caused the error (or -1 if not applicable). Note that
   142      * the list of certificates in a <code>CertPath</code> is zero based.
   142      * the list of certificates in a {@code CertPath} is zero based.
   143      * @throws IndexOutOfBoundsException if the index is out of range
   143      * @throws IndexOutOfBoundsException if the index is out of range
   144      * {@code (index < -1 || (certPath != null && index >=
   144      * {@code (index < -1 || (certPath != null && index >=
   145      * certPath.getCertificates().size()) }
   145      * certPath.getCertificates().size()) }
   146      * @throws IllegalArgumentException if <code>certPath</code> is
   146      * @throws IllegalArgumentException if {@code certPath} is
   147      * <code>null</code> and <code>index</code> is not -1
   147      * {@code null} and {@code index} is not -1
   148      */
   148      */
   149     public CertPathValidatorException(String msg, Throwable cause,
   149     public CertPathValidatorException(String msg, Throwable cause,
   150             CertPath certPath, int index) {
   150             CertPath certPath, int index) {
   151         this(msg, cause, certPath, index, BasicReason.UNSPECIFIED);
   151         this(msg, cause, certPath, index, BasicReason.UNSPECIFIED);
   152     }
   152     }
   153 
   153 
   154     /**
   154     /**
   155      * Creates a <code>CertPathValidatorException</code> with the specified
   155      * Creates a {@code CertPathValidatorException} with the specified
   156      * detail message, cause, certification path, index, and reason.
   156      * detail message, cause, certification path, index, and reason.
   157      *
   157      *
   158      * @param msg the detail message (or <code>null</code> if none)
   158      * @param msg the detail message (or {@code null} if none)
   159      * @param cause the cause (or <code>null</code> if none)
   159      * @param cause the cause (or {@code null} if none)
   160      * @param certPath the certification path that was in the process of
   160      * @param certPath the certification path that was in the process of
   161      * being validated when the error was encountered
   161      * being validated when the error was encountered
   162      * @param index the index of the certificate in the certification path
   162      * @param index the index of the certificate in the certification path
   163      * that caused the error (or -1 if not applicable). Note that
   163      * that caused the error (or -1 if not applicable). Note that
   164      * the list of certificates in a <code>CertPath</code> is zero based.
   164      * the list of certificates in a {@code CertPath} is zero based.
   165      * @param reason the reason the validation failed
   165      * @param reason the reason the validation failed
   166      * @throws IndexOutOfBoundsException if the index is out of range
   166      * @throws IndexOutOfBoundsException if the index is out of range
   167      * {@code (index < -1 || (certPath != null && index >=
   167      * {@code (index < -1 || (certPath != null && index >=
   168      * certPath.getCertificates().size()) }
   168      * certPath.getCertificates().size()) }
   169      * @throws IllegalArgumentException if <code>certPath</code> is
   169      * @throws IllegalArgumentException if {@code certPath} is
   170      * <code>null</code> and <code>index</code> is not -1
   170      * {@code null} and {@code index} is not -1
   171      * @throws NullPointerException if <code>reason</code> is <code>null</code>
   171      * @throws NullPointerException if {@code reason} is {@code null}
   172      *
   172      *
   173      * @since 1.7
   173      * @since 1.7
   174      */
   174      */
   175     public CertPathValidatorException(String msg, Throwable cause,
   175     public CertPathValidatorException(String msg, Throwable cause,
   176             CertPath certPath, int index, Reason reason) {
   176             CertPath certPath, int index, Reason reason) {
   192 
   192 
   193     /**
   193     /**
   194      * Returns the certification path that was being validated when
   194      * Returns the certification path that was being validated when
   195      * the exception was thrown.
   195      * the exception was thrown.
   196      *
   196      *
   197      * @return the <code>CertPath</code> that was being validated when
   197      * @return the {@code CertPath} that was being validated when
   198      * the exception was thrown (or <code>null</code> if not specified)
   198      * the exception was thrown (or {@code null} if not specified)
   199      */
   199      */
   200     public CertPath getCertPath() {
   200     public CertPath getCertPath() {
   201         return this.certPath;
   201         return this.certPath;
   202     }
   202     }
   203 
   203 
   204     /**
   204     /**
   205      * Returns the index of the certificate in the certification path
   205      * Returns the index of the certificate in the certification path
   206      * that caused the exception to be thrown. Note that the list of
   206      * that caused the exception to be thrown. Note that the list of
   207      * certificates in a <code>CertPath</code> is zero based. If no
   207      * certificates in a {@code CertPath} is zero based. If no
   208      * index has been set, -1 is returned.
   208      * index has been set, -1 is returned.
   209      *
   209      *
   210      * @return the index that has been set, or -1 if none has been set
   210      * @return the index that has been set, or -1 if none has been set
   211      */
   211      */
   212     public int getIndex() {
   212     public int getIndex() {
   217      * Returns the reason that the validation failed. The reason is
   217      * Returns the reason that the validation failed. The reason is
   218      * associated with the index of the certificate returned by
   218      * associated with the index of the certificate returned by
   219      * {@link #getIndex}.
   219      * {@link #getIndex}.
   220      *
   220      *
   221      * @return the reason that the validation failed, or
   221      * @return the reason that the validation failed, or
   222      *    <code>BasicReason.UNSPECIFIED</code> if a reason has not been
   222      *    {@code BasicReason.UNSPECIFIED} if a reason has not been
   223      *    specified
   223      *    specified
   224      *
   224      *
   225      * @since 1.7
   225      * @since 1.7
   226      */
   226      */
   227     public Reason getReason() {
   227     public Reason getReason() {