Path: blob/master/test/jdk/sun/security/x509/X509CRLImpl/UnexpectedNPE.java
41153 views
/*1* Copyright (c) 2004, 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 505243326* @summary NullPointerException for generateCRL and generateCRLs methods.27*/28import java.security.NoSuchProviderException;29import java.security.cert.*;30import java.io.ByteArrayInputStream;3132public class UnexpectedNPE {33CertificateFactory cf = null ;3435public UnexpectedNPE() {}3637public static void main( String[] av ) {38byte[] encoded_1 = { 0x00, 0x00, 0x00, 0x00 };39byte[] encoded_2 = { 0x30, 0x01, 0x00, 0x00 };40byte[] encoded_3 = { 0x30, 0x01, 0x00 };4142UnexpectedNPE unpe = new UnexpectedNPE() ;4344if(!unpe.run(encoded_1)) {45throw new SecurityException("CRLException has not been thrown");46}4748if(!unpe.run(encoded_2)) {49throw new SecurityException("CRLException has not been thrown");50}5152if(!unpe.run(encoded_2)) {53throw new SecurityException("CRLException has not been thrown");54}55}5657private boolean run(byte[] buf) {58if (cf == null) {59try {60cf = CertificateFactory.getInstance("X.509", "SUN");61} catch (CertificateException e) {62throw new SecurityException("Cannot get CertificateFactory");63} catch (NoSuchProviderException npe) {64throw new SecurityException("Cannot get CertificateFactory");65}66}67try {68cf.generateCRL(new ByteArrayInputStream(buf));69} catch (CRLException ce) {70System.out.println("NPE checking passed");71return true;72}7374System.out.println("CRLException has not been thrown");75return false;76}77}787980