Path: blob/master/test/jdk/java/net/SocketPermission/Ctor.java
41149 views
/*1* Copyright (c) 2001, 2019, 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 4391898 823040726* @summary SocketPermission(":",...) throws ArrayIndexOutOfBoundsException27* SocketPermission constructor argument checks28* @run testng Ctor29*/3031import java.net.SocketPermission;32import org.testng.annotations.Test;33import static java.lang.System.out;34import static org.testng.Assert.*;3536public class Ctor {3738static final Class<NullPointerException> NPE = NullPointerException.class;39static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class;4041@Test42public void positive() {43// ArrayIndexOutOfBoundsException is the bug, 4391898, exists44SocketPermission sp1 = new SocketPermission(":", "connect");45}4647@Test48public void npe() {49NullPointerException e;50e = expectThrows(NPE, () -> new SocketPermission(null, null));51out.println("caught expected NPE: " + e);52e = expectThrows(NPE, () -> new SocketPermission("foo", null));53out.println("caught expected NPE: " + e);54e = expectThrows(NPE, () -> new SocketPermission(null, "connect"));55out.println("caught expected NPE: " + e);56}5758@Test59public void iae() {60IllegalArgumentException e;61// host62e = expectThrows(IAE, () -> new SocketPermission("1:2:3:4", "connect"));63out.println("caught expected IAE: " + e);64e = expectThrows(IAE, () -> new SocketPermission("foo:5-4", "connect"));65out.println("caught expected IAE: " + e);6667// actions68e = expectThrows(IAE, () -> new SocketPermission("foo", ""));69out.println("caught expected IAE: " + e);70e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction"));71out.println("caught expected IAE: " + e);72e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction,connect"));73out.println("caught expected IAE: " + e);74e = expectThrows(IAE, () -> new SocketPermission("foo", "badAction,,connect"));75out.println("caught expected IAE: " + e);76e = expectThrows(IAE, () -> new SocketPermission("foo", ",connect"));77out.println("caught expected IAE: " + e);78e = expectThrows(IAE, () -> new SocketPermission("foo", ",,connect"));79out.println("caught expected IAE: " + e);80e = expectThrows(IAE, () -> new SocketPermission("foo", "connect,"));81out.println("caught expected IAE: " + e);82e = expectThrows(IAE, () -> new SocketPermission("foo", "connect,,"));83out.println("caught expected IAE: " + e);84}85}868788