253N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
253N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
253N/A *
253N/A * This code is free software; you can redistribute it and/or modify it
253N/A * under the terms of the GNU General Public License version 2 only, as
253N/A * published by the Free Software Foundation.
253N/A *
253N/A * This code is distributed in the hope that it will be useful, but WITHOUT
253N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
253N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
253N/A * version 2 for more details (a copy is included in the LICENSE file that
253N/A * accompanied this code).
253N/A *
253N/A * You should have received a copy of the GNU General Public License version
253N/A * 2 along with this work; if not, write to the Free Software Foundation,
253N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
253N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
253N/A */
253N/A
253N/A/*
253N/A * @test
253N/A * @bug 6631361
253N/A * @summary Test constructor when PD array is null or contains all null contexts
253N/A */
253N/A
253N/Aimport java.security.AccessControlContext;
253N/Aimport java.security.ProtectionDomain;
253N/A
253N/Apublic class CheckCtor {
253N/A
253N/A public static void main(String[] args) throws Exception {
253N/A
253N/A // check that null PD array throws NPE
253N/A try {
253N/A new AccessControlContext(null);
253N/A throw new Exception("Expected NullPointerException not thrown");
253N/A } catch (Exception e) {
253N/A if (!(e instanceof NullPointerException)) {
253N/A throw new Exception("Expected NullPointerException not thrown");
253N/A }
253N/A }
253N/A
253N/A // check that empty PD array equals PD array of one or more nulls
253N/A ProtectionDomain zero[] = {};
253N/A ProtectionDomain null1[] = {null};
253N/A ProtectionDomain null2[] = {null, null};
253N/A
253N/A AccessControlContext accZero = new AccessControlContext(zero);
253N/A AccessControlContext accNull1 = new AccessControlContext(null1);
253N/A AccessControlContext accNull2 = new AccessControlContext(null2);
253N/A
253N/A testEquals(accZero, accNull1);
253N/A testEquals(accZero, accNull2);
253N/A testEquals(accNull1, accNull2);
253N/A testEquals(accNull1, accZero);
253N/A testEquals(accNull2, accZero);
253N/A testEquals(accNull2, accNull1);
253N/A }
253N/A
253N/A private static void testEquals(AccessControlContext acc1,
253N/A AccessControlContext acc2) throws Exception {
253N/A if (!acc1.equals(acc2)) {
253N/A throw new Exception("AccessControlContexts should be equal");
253N/A }
253N/A }
253N/A}