jdk/test/java/security/AccessControlContext/CheckCtor.java
author jjg
Mon, 25 Nov 2013 17:42:28 -0800
changeset 21894 3535c1819067
parent 5506 202f599c92aa
permissions -rw-r--r--
8028318: [doclint] doclint will reject existing user-written doc comments using custom tags that follow the recommended rules Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
476
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 476
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
476
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     4
 *
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     8
 *
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    13
 * accompanied this code).
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    14
 *
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 476
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 476
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 476
diff changeset
    21
 * questions.
476
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    22
 */
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    23
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    24
/*
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    25
 * @test
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    26
 * @bug 6631361
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    27
 * @summary Test constructor when PD array is null or contains all null contexts
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    28
 */
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    29
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    30
import java.security.AccessControlContext;
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    31
import java.security.ProtectionDomain;
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    32
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    33
public class CheckCtor {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    34
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    36
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    37
        // check that null PD array throws NPE
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    38
        try {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    39
            new AccessControlContext(null);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    40
            throw new Exception("Expected NullPointerException not thrown");
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    41
        } catch (Exception e) {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    42
            if (!(e instanceof NullPointerException)) {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    43
                throw new Exception("Expected NullPointerException not thrown");
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    44
            }
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    45
        }
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    46
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    47
        // check that empty PD array equals PD array of one or more nulls
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    48
        ProtectionDomain zero[] = {};
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    49
        ProtectionDomain null1[] = {null};
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    50
        ProtectionDomain null2[] = {null, null};
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    51
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    52
        AccessControlContext accZero = new AccessControlContext(zero);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    53
        AccessControlContext accNull1 = new AccessControlContext(null1);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    54
        AccessControlContext accNull2 = new AccessControlContext(null2);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    55
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    56
        testEquals(accZero, accNull1);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    57
        testEquals(accZero, accNull2);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    58
        testEquals(accNull1, accNull2);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    59
        testEquals(accNull1, accZero);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    60
        testEquals(accNull2, accZero);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    61
        testEquals(accNull2, accNull1);
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    62
    }
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    63
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    64
    private static void testEquals(AccessControlContext acc1,
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    65
        AccessControlContext acc2) throws Exception {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    66
        if (!acc1.equals(acc2)) {
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    67
            throw new Exception("AccessControlContexts should be equal");
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    68
        }
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    69
    }
b23646c026ed 6631361: Spec of AccessControlContext constructor is not complete
mullan
parents:
diff changeset
    70
}