|
1 | 1 | /* |
2 | | - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
23 | 23 |
|
24 | 24 | /* |
25 | 25 | * @test |
26 | | - * @bug 5052433 |
27 | | - * @summary NullPointerException for generateCRL and generateCRLs methods. |
| 26 | + * @bug 5052433 8315042 |
| 27 | + * @summary Verify that generateCRL and generateCRLs methods do not throw |
| 28 | + * NullPointerException. They should throw CRLException instead. |
| 29 | + * @library /test/lib |
28 | 30 | */ |
29 | 31 | import java.security.NoSuchProviderException; |
30 | 32 | import java.security.cert.*; |
31 | 33 | import java.io.ByteArrayInputStream; |
| 34 | +import java.util.Base64; |
32 | 35 |
|
33 | | -public class UnexpectedNPE { |
34 | | - CertificateFactory cf = null ; |
| 36 | +import jdk.test.lib.Utils; |
35 | 37 |
|
36 | | - public UnexpectedNPE() {} |
| 38 | +public class UnexpectedNPE { |
| 39 | + static CertificateFactory cf = null; |
37 | 40 |
|
38 | | - public static void main( String[] av ) { |
| 41 | + public static void main(String[] av ) throws CertificateException, |
| 42 | + NoSuchProviderException { |
39 | 43 | byte[] encoded_1 = { 0x00, 0x00, 0x00, 0x00 }; |
40 | 44 | byte[] encoded_2 = { 0x30, 0x01, 0x00, 0x00 }; |
41 | 45 | byte[] encoded_3 = { 0x30, 0x01, 0x00 }; |
| 46 | + byte[] encoded_4 = Base64.getDecoder().decode( |
| 47 | + "MAsGCSqGSMP7TQEHAjI1Bgn///////8wCwUyAQ=="); |
42 | 48 |
|
43 | | - UnexpectedNPE unpe = new UnexpectedNPE() ; |
44 | | - |
45 | | - if(!unpe.run(encoded_1)) { |
46 | | - throw new SecurityException("CRLException has not been thrown"); |
47 | | - } |
| 49 | + cf = CertificateFactory.getInstance("X.509", "SUN"); |
48 | 50 |
|
49 | | - if(!unpe.run(encoded_2)) { |
50 | | - throw new SecurityException("CRLException has not been thrown"); |
51 | | - } |
52 | | - |
53 | | - if(!unpe.run(encoded_2)) { |
54 | | - throw new SecurityException("CRLException has not been thrown"); |
55 | | - } |
| 51 | + run(encoded_1); |
| 52 | + run(encoded_2); |
| 53 | + run(encoded_3); |
| 54 | + run(encoded_4); |
56 | 55 | } |
57 | 56 |
|
58 | | - private boolean run(byte[] buf) { |
59 | | - if (cf == null) { |
60 | | - try { |
61 | | - cf = CertificateFactory.getInstance("X.509", "SUN"); |
62 | | - } catch (CertificateException e) { |
63 | | - throw new SecurityException("Cannot get CertificateFactory"); |
64 | | - } catch (NoSuchProviderException npe) { |
65 | | - throw new SecurityException("Cannot get CertificateFactory"); |
66 | | - } |
67 | | - } |
68 | | - try { |
69 | | - cf.generateCRL(new ByteArrayInputStream(buf)); |
70 | | - } catch (CRLException ce) { |
71 | | - System.out.println("NPE checking passed"); |
72 | | - return true; |
73 | | - } |
74 | | - |
75 | | - System.out.println("CRLException has not been thrown"); |
76 | | - return false; |
| 57 | + private static void run(byte[] buf) { |
| 58 | + Utils.runAndCheckException( |
| 59 | + () -> cf.generateCRL(new ByteArrayInputStream(buf)), |
| 60 | + CRLException.class); |
| 61 | + Utils.runAndCheckException( |
| 62 | + () -> cf.generateCRLs(new ByteArrayInputStream(buf)), |
| 63 | + CRLException.class); |
77 | 64 | } |
78 | 65 | } |
0 commit comments