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