Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/security/BasicPermission/NullOrEmptyName.java
38812 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*/3031public class NullOrEmptyName {3233public static void main(String[]args) throws Exception {34NullOrEmptyName noe = new NullOrEmptyName();3536// run without sm installed37noe.run();3839// run with sm installed40SecurityManager sm = new SecurityManager();41System.setSecurityManager(sm);42noe.run();4344try {45// called by System.getProperty()46sm.checkPropertyAccess(null);47throw new Exception("Expected NullPointerException not thrown");48} catch (NullPointerException npe) {49// expected exception thrown50}5152try {53// called by System.getProperty()54sm.checkPropertyAccess("");55throw new Exception("Expected IllegalArgumentException not " +56"thrown");57} catch (IllegalArgumentException iae) {58// expected exception thrown59}60}6162void run() throws Exception {6364try {65System.getProperty(null);66throw new Exception("Expected NullPointerException not " +67"thrown");68} catch (NullPointerException npe) {69// expected exception thrown70}7172try {73System.getProperty(null, "value");74throw new Exception("Expected NullPointerException not " +75"thrown");76} catch (NullPointerException npe) {77// expected exception thrown78}7980try {81System.getProperty("");82throw new Exception("Expected IllegalArgumentException not " +83"thrown");84} catch (IllegalArgumentException iae) {85// expected exception thrown86}8788try {89System.getProperty("", "value");90throw new Exception("Expected IllegalArgumentException not " +91"thrown");92} catch (IllegalArgumentException iae) {93// expected exception thrown94}9596try {97System.setProperty(null, "value");98throw new Exception("Expected NullPointerException not " +99"thrown");100} catch (NullPointerException npe) {101// expected exception thrown102}103104try {105System.setProperty("", "value");106throw new Exception("Expected IllegalArgumentException not " +107"thrown");108} catch (IllegalArgumentException iae) {109// expected exception thrown110}111}112}113114115