1 /* |
1 /* |
2 * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 4391898 |
26 * @bug 4391898 8230407 |
27 * @summary SocketPermission(":",...) throws ArrayIndexOutOfBoundsException |
27 * @summary SocketPermission(":",...) throws ArrayIndexOutOfBoundsException |
|
28 * SocketPermission constructor argument checks |
|
29 * @run testng Ctor |
28 */ |
30 */ |
29 |
31 |
30 import java.net.*; |
32 import java.net.SocketPermission; |
|
33 import org.testng.annotations.Test; |
|
34 import static java.lang.System.out; |
|
35 import static org.testng.Assert.*; |
31 |
36 |
32 public class Ctor { |
37 public class Ctor { |
33 public static void main(String[] args) { |
38 |
34 try { |
39 static final Class<NullPointerException> NPE = NullPointerException.class; |
35 SocketPermission sp = new java.net.SocketPermission(":", "connect"); |
40 static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; |
36 } catch (java.lang.ArrayIndexOutOfBoundsException e) { |
41 |
37 throw new RuntimeException(e); |
42 @Test |
38 } |
43 public void positive() { |
39 System.out.println("Test passed!!!"); |
44 // ArrayIndexOutOfBoundsException is the bug, 4391898, exists |
|
45 SocketPermission sp1 = new SocketPermission(":", "connect"); |
|
46 } |
|
47 |
|
48 @Test |
|
49 public void npe() { |
|
50 NullPointerException e; |
|
51 e = expectThrows(NPE, () -> new SocketPermission(null, null)); |
|
52 out.println("caught expected NPE: " + e); |
|
53 e = expectThrows(NPE, () -> new SocketPermission("foo", null)); |
|
54 out.println("caught expected NPE: " + e); |
|
55 e = expectThrows(NPE, () -> new SocketPermission(null, "connect")); |
|
56 out.println("caught expected NPE: " + e); |
|
57 } |
|
58 |
|
59 @Test |
|
60 public void iae() { |
|
61 IllegalArgumentException e; |
|
62 // host |
|
63 e = expectThrows(IAE, () -> new SocketPermission("1:2:3:4", "connect")); |
|
64 out.println("caught expected IAE: " + e); |
|
65 e = expectThrows(IAE, () -> new SocketPermission("foo:5-4", "connect")); |
|
66 out.println("caught expected IAE: " + e); |
|
67 |
|
68 // actions |
|
69 e = expectThrows(IAE, () -> new SocketPermission("foo", "")); |
|
70 out.println("caught expected IAE: " + e); |
|
71 e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction")); |
|
72 out.println("caught expected IAE: " + e); |
|
73 e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction,connect")); |
|
74 out.println("caught expected IAE: " + e); |
|
75 e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction,,connect")); |
|
76 out.println("caught expected IAE: " + e); |
|
77 e = expectThrows(IAE, () -> new SocketPermission("foo", ",connect")); |
|
78 out.println("caught expected IAE: " + e); |
|
79 e = expectThrows(IAE, () -> new SocketPermission("foo", ",,connect")); |
|
80 out.println("caught expected IAE: " + e); |
|
81 e = expectThrows(IAE, () -> new SocketPermission("foo", "connect,")); |
|
82 out.println("caught expected IAE: " + e); |
|
83 e = expectThrows(IAE, () -> new SocketPermission("foo", "connect,,")); |
|
84 out.println("caught expected IAE: " + e); |
40 } |
85 } |
41 } |
86 } |