Path: blob/master/test/jdk/java/security/AccessControlContext/CheckCtor.java
41149 views
/*1* Copyright (c) 2008, 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 663136126* @summary Test constructor when PD array is null or contains all null contexts27*/2829import java.security.AccessControlContext;30import java.security.ProtectionDomain;3132public class CheckCtor {3334public static void main(String[] args) throws Exception {3536// check that null PD array throws NPE37try {38new AccessControlContext(null);39throw new Exception("Expected NullPointerException not thrown");40} catch (Exception e) {41if (!(e instanceof NullPointerException)) {42throw new Exception("Expected NullPointerException not thrown");43}44}4546// check that empty PD array equals PD array of one or more nulls47ProtectionDomain zero[] = {};48ProtectionDomain null1[] = {null};49ProtectionDomain null2[] = {null, null};5051AccessControlContext accZero = new AccessControlContext(zero);52AccessControlContext accNull1 = new AccessControlContext(null1);53AccessControlContext accNull2 = new AccessControlContext(null2);5455testEquals(accZero, accNull1);56testEquals(accZero, accNull2);57testEquals(accNull1, accNull2);58testEquals(accNull1, accZero);59testEquals(accNull2, accZero);60testEquals(accNull2, accNull1);61}6263private static void testEquals(AccessControlContext acc1,64AccessControlContext acc2) throws Exception {65if (!acc1.equals(acc2)) {66throw new Exception("AccessControlContexts should be equal");67}68}69}707172