jdk/test/tools/launcher/VerifyExceptions.java
author ksrini
Mon, 28 Jun 2010 18:25:03 -0700
changeset 5982 de622fe4f7d8
permissions -rw-r--r--
6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found ) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5982
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     1
/*
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     4
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     7
 * published by the Free Software Foundation.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     8
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    13
 * accompanied this code).
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    14
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    18
 *
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    21
 * questions.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    22
 */
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    23
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    24
/*
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    25
 * @test
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    26
 * @bug 6856415
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    27
 * @summary Checks to ensure that proper exceptions are thrown by java
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    28
 * @compile -XDignore.symbol.file VerifyExceptions.java TestHelper.java
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    29
 * @run main VerifyExceptions
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    30
 */
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    31
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    32
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    33
import java.io.File;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    34
import java.io.FileNotFoundException;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    35
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    36
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    37
public class VerifyExceptions {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    38
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    39
    static void test6856415() {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    40
        // No pkcs library on win-x64, so we bail out.
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    41
        if (TestHelper.is64Bit && TestHelper.isWindows) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    42
            return;
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    43
        }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    44
        StringBuilder sb = new StringBuilder();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    45
        sb.append("public static void main(String... args) {\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    46
        sb.append("java.security.Provider p = new sun.security.pkcs11.SunPKCS11(args[0]);\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    47
        sb.append("java.security.Security.insertProviderAt(p, 1);\n");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    48
        sb.append("}");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    49
        File testJar = new File("Foo.jar");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    50
        testJar.delete();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    51
        try {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    52
            TestHelper.createJar(testJar, sb.toString());
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    53
        } catch (FileNotFoundException fnfe) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    54
            throw new RuntimeException(fnfe);
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    55
        }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    56
        TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javacCmd,
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    57
                "-Djava.security.manager", "-jar", testJar.getName(), "foo.bak");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    58
        tr.checkNegative();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    59
        tr.contains("Exception in thread \"main\" java.security.AccessControlException: access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.security.pkcs11\")\")");
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    60
    }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    61
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    62
    public static void main(String... args) {
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    63
        test6856415();
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    64
    }
de622fe4f7d8 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found )
ksrini
parents:
diff changeset
    65
}