1/* 2 * Copyright (c) 2004, 2007, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 5032952 27 * @summary non-transient non-serializable instance field in 28 serializable class 29 * @modules java.base/sun.security.provider.certpath 30 */ 31 32import sun.security.provider.certpath.SunCertPathBuilderException; 33import java.io.*; 34import java.security.cert.*; 35import java.security.*; 36import java.util.Collections; 37 38public class SunCertPathBuilderExceptionTest { 39 40 public static void main(String[] args) throws Exception { 41 try { 42 CertPathBuilder cpb = CertPathBuilder. 43 getInstance(CertPathBuilder.getDefaultType()); 44 CertificateFactory cf = CertificateFactory.getInstance("X.509"); 45 File f = new File 46 (System.getProperty("test.src", "."), "speech2speech"); 47 X509Certificate cert = (X509Certificate) 48 cf.generateCertificate(new FileInputStream(f)); 49 TrustAnchor anchor = new TrustAnchor(cert, null); 50 51 X509CertSelector xs = new X509CertSelector(); 52 53 // a non-exist subject which will ruin the builder soon 54 xs.setSubject("CN=A, OU=A, O=A, L=A, ST=A, C=A"); 55 PKIXBuilderParameters pkp = 56 new PKIXBuilderParameters(Collections.singleton(anchor), xs); 57 cpb.build(pkp); 58 } catch(SunCertPathBuilderException e) { 59 System.out.println("Got the Exception: "); 60 try { 61 ObjectOutputStream o = 62 new ObjectOutputStream(new ByteArrayOutputStream()); 63 o.writeObject(e); 64 o.close(); 65 } catch(NotSerializableException e2) { 66 System.out.println("Test fail: bug not corrected"); 67 throw e2; 68 } 69 System.out.println("Test pass: SCPEE is Serializable"); 70 return; 71 } 72 throw new Exception("Test fail: Strange, no SCPEE thrown"); 73 } 74} 75