1. /*
  2. * @(#)CertPathValidatorException.java 1.10 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.security.GeneralSecurityException;
  9. /**
  10. * An exception indicating one of a variety of problems encountered when
  11. * validating a certification path.
  12. * <p>
  13. * A <code>CertPathValidatorException</code> provides support for wrapping
  14. * exceptions. The {@link #getCause getCause} method returns the throwable,
  15. * if any, that caused this exception to be thrown.
  16. * <p>
  17. * A <code>CertPathValidatorException</code> may also include the
  18. * certification path that was being validated when the exception was thrown
  19. * and the index of the certificate in the certification path that caused the
  20. * exception to be thrown. Use the {@link #getCertPath getCertPath} and
  21. * {@link #getIndex getIndex} methods to retrieve this information.
  22. *
  23. * <p>
  24. * <b>Concurrent Access</b>
  25. * <p>
  26. * Unless otherwise specified, the methods defined in this class are not
  27. * thread-safe. Multiple threads that need to access a single
  28. * object concurrently should synchronize amongst themselves and
  29. * provide the necessary locking. Multiple threads each manipulating
  30. * separate objects need not synchronize.
  31. *
  32. * @see CertPathValidator
  33. *
  34. * @version 1.10 12/19/03
  35. * @since 1.4
  36. * @author Yassir Elley
  37. */
  38. public class CertPathValidatorException extends GeneralSecurityException {
  39. private static final long serialVersionUID = -3083180014971893139L;
  40. /**
  41. * @serial the index of the certificate in the certification path
  42. * that caused the exception to be thrown
  43. */
  44. private int index = -1;
  45. /**
  46. * @serial the <code>CertPath</code> that was being validated when
  47. * the exception was thrown
  48. */
  49. private CertPath certPath;
  50. /**
  51. * Creates a <code>CertPathValidatorException</code> with
  52. * no detail message.
  53. */
  54. public CertPathValidatorException() {
  55. super();
  56. }
  57. /**
  58. * Creates a <code>CertPathValidatorException</code> with the given
  59. * detail message. A detail message is a <code>String</code> that
  60. * describes this particular exception.
  61. *
  62. * @param msg the detail message
  63. */
  64. public CertPathValidatorException(String msg) {
  65. super(msg);
  66. }
  67. /**
  68. * Creates a <code>CertPathValidatorException</code> that wraps the
  69. * specified throwable. This allows any exception to be converted into a
  70. * <code>CertPathValidatorException</code>, while retaining information
  71. * about the wrapped exception, which may be useful for debugging. The
  72. * detail message is set to (<code>cause==null ? null : cause.toString()
  73. * </code>) (which typically contains the class and detail message of
  74. * cause).
  75. *
  76. * @param cause the cause (which is saved for later retrieval by the
  77. * {@link #getCause getCause()} method). (A <code>null</code> value is
  78. * permitted, and indicates that the cause is nonexistent or unknown.)
  79. */
  80. public CertPathValidatorException(Throwable cause) {
  81. super(cause);
  82. }
  83. /**
  84. * Creates a <code>CertPathValidatorException</code> with the specified
  85. * detail message and cause.
  86. *
  87. * @param msg the detail message
  88. * @param cause the cause (which is saved for later retrieval by the
  89. * {@link #getCause getCause()} method). (A <code>null</code> value is
  90. * permitted, and indicates that the cause is nonexistent or unknown.)
  91. */
  92. public CertPathValidatorException(String msg, Throwable cause) {
  93. super(msg, cause);
  94. }
  95. /**
  96. * Creates a <code>CertPathValidatorException</code> with the specified
  97. * detail message, cause, certification path, and index.
  98. *
  99. * @param msg the detail message (or <code>null</code> if none)
  100. * @param cause the cause (or <code>null</code> if none)
  101. * @param certPath the certification path that was in the process of
  102. * being validated when the error was encountered
  103. * @param index the index of the certificate in the certification path
  104. * that caused the error (or -1 if not applicable). Note that
  105. * the list of certificates in a <code>CertPath</code> is zero based.
  106. * @throws IndexOutofBoundsException if the index is out of range
  107. * <code>(index < -1 || (certPath != null && index >=
  108. * certPath.getCertificates().size())</code>
  109. * @throws IllegalArgumentException if <code>certPath</code> is
  110. * <code>null</code> and <code>index</code> is not -1
  111. */
  112. public CertPathValidatorException(String msg, Throwable cause,
  113. CertPath certPath, int index) {
  114. super(msg, cause);
  115. if (certPath == null && index != -1) {
  116. throw new IllegalArgumentException();
  117. }
  118. if (index < -1 ||
  119. (certPath != null && index >= certPath.getCertificates().size())) {
  120. throw new IndexOutOfBoundsException();
  121. }
  122. this.certPath = certPath;
  123. this.index = index;
  124. }
  125. /**
  126. * Returns the certification path that was being validated when
  127. * the exception was thrown.
  128. *
  129. * @return the <code>CertPath</code> that was being validated when
  130. * the exception was thrown (or <code>null</code> if not specified)
  131. */
  132. public CertPath getCertPath() {
  133. return this.certPath;
  134. }
  135. /**
  136. * Returns the index of the certificate in the certification path
  137. * that caused the exception to be thrown. Note that the list of
  138. * certificates in a <code>CertPath</code> is zero based. If no
  139. * index has been set, -1 is returned.
  140. *
  141. * @return the index that has been set, or -1 if none has been set
  142. */
  143. public int getIndex() {
  144. return this.index;
  145. }
  146. }