6557615: Method toString() of java.security.Timestamp throws IndexOutOfBoundsException if CertPath has empty
Reviewed-by: mullan
--- 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();
}