Path: blob/master/test/jdk/java/security/BasicPermission/NullOrEmptyName.java
41149 views
/*1* Copyright (c) 1999, 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 424025226* @summary Make sure BasicPermission constructor raises27* NullPointerException if permission name is null, and28* IllegalArgumentException is permission name is empty.29* @run main/othervm -Djava.security.manager=allow NullOrEmptyName30*/3132public class NullOrEmptyName {3334public static void main(String[]args) throws Exception {35NullOrEmptyName noe = new NullOrEmptyName();3637// run without sm installed38noe.run();3940// run with sm installed41SecurityManager sm = new SecurityManager();42System.setSecurityManager(sm);43noe.run();4445try {46// called by System.getProperty()47sm.checkPropertyAccess(null);48throw new Exception("Expected NullPointerException not thrown");49} catch (NullPointerException npe) {50// expected exception thrown51}5253try {54// called by System.getProperty()55sm.checkPropertyAccess("");56throw new Exception("Expected IllegalArgumentException not " +57"thrown");58} catch (IllegalArgumentException iae) {59// expected exception thrown60}61}6263void run() throws Exception {6465try {66System.getProperty(null);67throw new Exception("Expected NullPointerException not " +68"thrown");69} catch (NullPointerException npe) {70// expected exception thrown71}7273try {74System.getProperty(null, "value");75throw new Exception("Expected NullPointerException not " +76"thrown");77} catch (NullPointerException npe) {78// expected exception thrown79}8081try {82System.getProperty("");83throw new Exception("Expected IllegalArgumentException not " +84"thrown");85} catch (IllegalArgumentException iae) {86// expected exception thrown87}8889try {90System.getProperty("", "value");91throw new Exception("Expected IllegalArgumentException not " +92"thrown");93} catch (IllegalArgumentException iae) {94// expected exception thrown95}9697try {98System.setProperty(null, "value");99throw new Exception("Expected NullPointerException not " +100"thrown");101} catch (NullPointerException npe) {102// expected exception thrown103}104105try {106System.setProperty("", "value");107throw new Exception("Expected IllegalArgumentException not " +108"thrown");109} catch (IllegalArgumentException iae) {110// expected exception thrown111}112}113}114115116