LimitedDoPrivilegedWithNullPerms.java revision 17113:d17577d4839b
1/*
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 8050281
27 * @summary Test that NullPointerException is thrown if any element of perms
28 * parameter is null
29 * @run testng LimitedDoPrivilegedWithNullPerms
30 */
31import java.security.AccessControlContext;
32import java.security.AccessController;
33import java.security.Permission;
34import java.security.PrivilegedAction;
35import java.security.PrivilegedActionException;
36import java.security.PrivilegedExceptionAction;
37import java.util.PropertyPermission;
38import org.testng.annotations.Test;
39
40public class LimitedDoPrivilegedWithNullPerms {
41
42    AccessControlContext acc = AccessController.getContext();
43    Permission p1 = new PropertyPermission("user.name", "read");
44
45    @Test(expectedExceptions = NullPointerException.class)
46    public void test1() {
47        AccessController.doPrivileged(
48                (PrivilegedAction<Void>) () -> null, acc, null);
49    }
50
51    @Test(expectedExceptions = NullPointerException.class)
52    public void test2() {
53        AccessController.doPrivileged(
54                (PrivilegedAction<Void>) () -> null, acc, p1, null);
55    }
56
57    @Test(expectedExceptions = NullPointerException.class)
58    public void test3() {
59        AccessController.doPrivilegedWithCombiner(
60                (PrivilegedAction<Void>) () -> null, acc, null);
61    }
62
63    @Test(expectedExceptions = NullPointerException.class)
64    public void test4() {
65        AccessController.doPrivilegedWithCombiner(
66                (PrivilegedAction<Void>) () -> null, acc, p1, null);
67    }
68
69    @Test(expectedExceptions = NullPointerException.class)
70    public void test5() throws PrivilegedActionException {
71        AccessController.doPrivileged(
72                (PrivilegedExceptionAction<Void>) () -> null,
73                acc, null);
74    }
75
76    @Test(expectedExceptions = NullPointerException.class)
77    public void test6() throws PrivilegedActionException {
78        AccessController.doPrivileged(
79                (PrivilegedExceptionAction<Void>) () -> null,
80                acc, p1, null);
81    }
82
83    @Test(expectedExceptions = NullPointerException.class)
84    public void test7() throws PrivilegedActionException {
85        AccessController.doPrivilegedWithCombiner(
86                (PrivilegedExceptionAction<Void>) () -> null,
87                acc, null);
88    }
89
90    @Test(expectedExceptions = NullPointerException.class)
91    public void test8() throws PrivilegedActionException {
92        AccessController.doPrivilegedWithCombiner(
93                (PrivilegedExceptionAction<Void>) () -> null,
94                acc, p1, null);
95    }
96}
97