Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-2179327

Method toString() of java.security.Timestamp throws IndexOutOfBoundsException if CertPath has empty

XMLWordPrintable

    • b123
    • Not verified

      The issue is reproducible on JDK7 b120, b119, b118, b100.

      Please see at the following test:
      -------------------------------------------------------
      import java.security.Timestamp;
      import java.security.cert.CertPath;
      import java.security.cert.Certificate;
      import java.security.cert.CertificateEncodingException;
      import java.util.Collections;
      import java.util.Date;
      import java.util.Iterator;
      import java.util.List;

      public class TimestampTest {
          public static void main(String[] args) {
              Timestamp ts = new Timestamp(new Date(), new CertPathStub("type"));
              System.out.println("toString:" + ts.toString());
          }
      }
      class CertPathStub extends CertPath {
          public Iterator<String> getEncodings() {
              return null;
          }
          public byte[] getEncoded() throws CertificateEncodingException {
              return null;
          }
          public byte[] getEncoded(String encoding)
                  throws CertificateEncodingException {
              return null;
          }
          public List<? extends Certificate> getCertificates() {
              return Collections.EMPTY_LIST;
          }
          protected CertPathStub(String type) {
              super(type);
          }
      }
      -------------------------------------------------------

      It's output is:
      -------------------------------------------------------
      Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0
              at java.util.Collections$EmptyList.get(Collections.java:3205)
              at java.security.Timestamp.toString(Timestamp.java:145)
              at TimestampTest.main(TimestampTest.java:13)
      -------------------------------------------------------

      Since the spec for CertPath.getCertificates() states
      "Returns: an immutable List of Certificates (may be empty, but not null)"
      the implementation behaviour is erroneous.

            vinnie Vincent Ryan
            pjr Paul Rank (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: