Path: blob/master/test/jdk/java/security/AccessController/LimitedDoPrivilegedWithNullPerms.java
41149 views
/*1* Copyright (c) 2013, 2014, 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 805028126* @summary Test that NullPointerException is thrown if any element of perms27* parameter is null28* @run testng LimitedDoPrivilegedWithNullPerms29*/30import java.security.AccessControlContext;31import java.security.AccessController;32import java.security.Permission;33import java.security.PrivilegedAction;34import java.security.PrivilegedActionException;35import java.security.PrivilegedExceptionAction;36import java.util.PropertyPermission;37import org.testng.annotations.Test;3839public class LimitedDoPrivilegedWithNullPerms {4041AccessControlContext acc = AccessController.getContext();42Permission p1 = new PropertyPermission("user.name", "read");4344@Test(expectedExceptions = NullPointerException.class)45public void test1() {46AccessController.doPrivileged(47(PrivilegedAction<Void>) () -> null, acc, null);48}4950@Test(expectedExceptions = NullPointerException.class)51public void test2() {52AccessController.doPrivileged(53(PrivilegedAction<Void>) () -> null, acc, p1, null);54}5556@Test(expectedExceptions = NullPointerException.class)57public void test3() {58AccessController.doPrivilegedWithCombiner(59(PrivilegedAction<Void>) () -> null, acc, null);60}6162@Test(expectedExceptions = NullPointerException.class)63public void test4() {64AccessController.doPrivilegedWithCombiner(65(PrivilegedAction<Void>) () -> null, acc, p1, null);66}6768@Test(expectedExceptions = NullPointerException.class)69public void test5() throws PrivilegedActionException {70AccessController.doPrivileged(71(PrivilegedExceptionAction<Void>) () -> null,72acc, null);73}7475@Test(expectedExceptions = NullPointerException.class)76public void test6() throws PrivilegedActionException {77AccessController.doPrivileged(78(PrivilegedExceptionAction<Void>) () -> null,79acc, p1, null);80}8182@Test(expectedExceptions = NullPointerException.class)83public void test7() throws PrivilegedActionException {84AccessController.doPrivilegedWithCombiner(85(PrivilegedExceptionAction<Void>) () -> null,86acc, null);87}8889@Test(expectedExceptions = NullPointerException.class)90public void test8() throws PrivilegedActionException {91AccessController.doPrivilegedWithCombiner(92(PrivilegedExceptionAction<Void>) () -> null,93acc, p1, null);94}95}969798