From f9067f6bd91312f28d1b6732141a4da1c9944eed Mon Sep 17 00:00:00 2001 From: ksrini Date: Mon, 28 Jun 2010 18:25:03 -0700 Subject: [PATCH] 6856415: Enabling java security manager will make programe thrown wrong exception ( main method not found ) Reviewed-by: darcy --- .../classes/sun/launcher/LauncherHelper.java | 7 +- jdk/test/tools/launcher/VerifyExceptions.java | 65 +++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 jdk/test/tools/launcher/VerifyExceptions.java diff --git a/jdk/src/share/classes/sun/launcher/LauncherHelper.java b/jdk/src/share/classes/sun/launcher/LauncherHelper.java index dc89f23da7..cba795968c 100644 --- a/jdk/src/share/classes/sun/launcher/LauncherHelper.java +++ b/jdk/src/share/classes/sun/launcher/LauncherHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -208,7 +208,7 @@ public enum LauncherHelper { Method method = null; try { method = clazz.getMethod("main", String[].class); - } catch (Exception e) { + } catch (NoSuchMethodException nsme) { ostream.println(getLocalizedMessage("java.launcher.cls.error4", classname)); throw new RuntimeException("Main method not found in " + classname); @@ -225,8 +225,7 @@ public enum LauncherHelper { throw new RuntimeException("Main method is not static in class " + classname); } - Class rType = method.getReturnType(); - if (!rType.isPrimitive() || !rType.getName().equals("void")) { + if (method.getReturnType() != java.lang.Void.TYPE) { ostream.println(getLocalizedMessage("java.launcher.cls.error3", classname)); throw new RuntimeException("Main method must return a value" + diff --git a/jdk/test/tools/launcher/VerifyExceptions.java b/jdk/test/tools/launcher/VerifyExceptions.java new file mode 100644 index 0000000000..166ffff9b1 --- /dev/null +++ b/jdk/test/tools/launcher/VerifyExceptions.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 6856415 + * @summary Checks to ensure that proper exceptions are thrown by java + * @compile -XDignore.symbol.file VerifyExceptions.java TestHelper.java + * @run main VerifyExceptions + */ + + +import java.io.File; +import java.io.FileNotFoundException; + + +public class VerifyExceptions { + + static void test6856415() { + // No pkcs library on win-x64, so we bail out. + if (TestHelper.is64Bit && TestHelper.isWindows) { + return; + } + StringBuilder sb = new StringBuilder(); + sb.append("public static void main(String... args) {\n"); + sb.append("java.security.Provider p = new sun.security.pkcs11.SunPKCS11(args[0]);\n"); + sb.append("java.security.Security.insertProviderAt(p, 1);\n"); + sb.append("}"); + File testJar = new File("Foo.jar"); + testJar.delete(); + try { + TestHelper.createJar(testJar, sb.toString()); + } catch (FileNotFoundException fnfe) { + throw new RuntimeException(fnfe); + } + TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javacCmd, + "-Djava.security.manager", "-jar", testJar.getName(), "foo.bak"); + tr.checkNegative(); + tr.contains("Exception in thread \"main\" java.security.AccessControlException: access denied (\"java.lang.RuntimePermission\" \"accessClassInPackage.sun.security.pkcs11\")\")"); + } + + public static void main(String... args) { + test6856415(); + } +} -- GitLab