From 08b28be8755aefef8268dc91a69ccaf0d136c201 Mon Sep 17 00:00:00 2001 From: robm Date: Tue, 28 Mar 2017 15:46:05 +0100 Subject: [PATCH] 8174113: Better sourcing of code Reviewed-by: weijun --- src/share/classes/java/security/CodeSource.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/share/classes/java/security/CodeSource.java b/src/share/classes/java/security/CodeSource.java index 62a5959ec..d00cbe336 100644 --- a/src/share/classes/java/security/CodeSource.java +++ b/src/share/classes/java/security/CodeSource.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, 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 @@ -535,6 +535,7 @@ public class CodeSource implements java.io.Serializable { { CertificateFactory cf; Hashtable cfs = null; + List certList = null; ois.defaultReadObject(); // location @@ -544,7 +545,7 @@ public class CodeSource implements java.io.Serializable { // we know of 3 different cert types: X.509, PGP, SDSI, which // could all be present in the stream at the same time cfs = new Hashtable(3); - this.certs = new java.security.cert.Certificate[size]; + certList = new ArrayList<>(size > 20 ? 20 : size); } for (int i = 0; i < size; i++) { @@ -575,13 +576,17 @@ public class CodeSource implements java.io.Serializable { ois.readFully(encoded); ByteArrayInputStream bais = new ByteArrayInputStream(encoded); try { - this.certs[i] = cf.generateCertificate(bais); + certList.add(cf.generateCertificate(bais)); } catch (CertificateException ce) { throw new IOException(ce.getMessage()); } bais.close(); } + if (certList != null) { + this.certs = certList.toArray( + new java.security.cert.Certificate[size]); + } // Deserialize array of code signers (if any) try { this.signers = ((CodeSigner[])ois.readObject()).clone(); -- GitLab