6557615: Method toString() of java.security.Timestamp throws IndexOutOfBoundsException if CertPath has empty
authorvinnie
Mon, 06 Dec 2010 18:52:23 +0000
changeset 7530 8f4072a653f0
parent 7529 226923903075
child 7531 77870839c857
child 7548 1460351b32bc
6557615: Method toString() of java.security.Timestamp throws IndexOutOfBoundsException if CertPath has empty Reviewed-by: mullan
jdk/src/share/classes/java/security/Timestamp.java
--- a/jdk/src/share/classes/java/security/Timestamp.java	Sun Dec 05 20:46:23 2010 -0800
+++ b/jdk/src/share/classes/java/security/Timestamp.java	Mon Dec 06 18:52:23 2010 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,9 +26,11 @@
 package java.security;
 
 import java.io.Serializable;
+import java.security.cert.Certificate;
 import java.security.cert.CertPath;
 import java.security.cert.X509Extension;
 import java.util.Date;
+import java.util.List;
 
 /**
  * This class encapsulates information about a signed timestamp.
@@ -142,7 +144,12 @@
         StringBuffer sb = new StringBuffer();
         sb.append("(");
         sb.append("timestamp: " + timestamp);
-        sb.append("TSA: " + signerCertPath.getCertificates().get(0));
+        List<? extends Certificate> certs = signerCertPath.getCertificates();
+        if (!certs.isEmpty()) {
+            sb.append("TSA: " + certs.get(0));
+        } else {
+            sb.append("TSA: <empty>");
+        }
         sb.append(")");
         return sb.toString();
     }