jdk/test/sun/security/provider/PolicyFile/BadPolicyFile.java
author jlaskey
Fri, 20 May 2016 11:41:29 -0300
changeset 38445 0a88d86065f9
parent 38324 1ecea77815a8
permissions -rw-r--r--
8156602: javac crashes again on Windows 32-bit with ClosedChannelException Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38324
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     1
/*
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     4
 *
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     8
 *
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    13
 * accompanied this code).
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    14
 *
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    18
 *
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    21
 * questions.
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    22
 */
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    23
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    24
/*
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    25
 * @test
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    26
 * @bug 8150468
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    27
 * @summary check that a badly formatted policy file is handled correctly
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    28
 * @run main/othervm BadPolicyFile
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    29
 */
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    30
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    31
import java.io.File;
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    32
import java.net.URI;
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    33
import java.security.AccessControlException;
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    34
import java.security.Policy;
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    35
import java.security.URIParameter;
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    36
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    37
public class BadPolicyFile {
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    38
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    40
        URI uri = new File(System.getProperty("test.src", "."),
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    41
                           "BadPolicyFile.policy").toURI();
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    42
        Policy.setPolicy(Policy.getInstance("JavaPolicy", new URIParameter(uri)));
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    43
        System.setSecurityManager(new SecurityManager());
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    44
        try {
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    45
            String javahome = System.getProperty("java.home");
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    46
            throw new Exception("Expected AccessControlException");
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    47
        } catch (AccessControlException ace) {
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    48
            System.out.println("Test PASSED");
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    49
        }
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    50
    }
1ecea77815a8 8150468: ClassCircularityError on error in security policy file
mullan
parents:
diff changeset
    51
}