JDK-6856415 : Enabling java security manager will make programe thrown wrong exception ( main method not found )
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-07-01
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b102Fixed
Related Reports
Relates :  
Description
Here is a very simple code to reproduce it : 

========================
bash-3.00$ cat Test.java
import java.security.*;
import sun.security.pkcs11.SunPKCS11;

public class Test {

    public static void main(String[] args) throws Exception {

            Provider p = new SunPKCS11(args[0]);
            Security.insertProviderAt(p, 1);

   }

}

============= Run with B62 =================

bash-3.00$  /java/re/jdk/7.0/promoted/all/b62/binaries/solaris-sparc/bin/javac Test.java
bash-3.00$  /java/re/jdk/7.0/promoted/all/b62/binaries/solaris-sparc/bin/java -Djava.security.manager Test ecprovider.cfg.bak
Error: Main method not found in class Test, please define the main method as:
   public static void main(String[] args)
Exception in thread "main" java.lang.RuntimeException: Main method not found in Test
        at sun.launcher.LauncherHelper.signatureDiagnostic(LauncherHelper.java:214)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:202)

===============Run with b35======================

bash-3.00$ /java/re/jdk/7.0/promoted/all/b35/binaries/solaris-sparc/bin/javac Test.java
bash-3.00$ /java/re/jdk/7.0/promoted/all/b35/binaries/solaris-sparc/bin/java Test ecprovider.cfg.bak
bash-3.00$ /java/re/jdk/7.0/promoted/all/b35/binaries/solaris-sparc/bin/java -Djava.security.manager Test ecprovider.cfg.bak
Exception in thread "main" java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.security.pkcs11)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:345)
        at java.security.AccessController.checkPermission(AccessController.java:555)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1529)
        at java.lang.ClassLoader$1.run(ClassLoader.java:349)
        at java.lang.ClassLoader$1.run(ClassLoader.java:347)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.lang.ClassLoader.checkPackageAccess(ClassLoader.java:347)
Error: Could not find the main class Test.
Error: A JNI error has occurred, please check your installation and try again

================================
When running with b62 , and enable java.security.manager , it thrown "Main method not found" RuntimeException , this is not the correct exception. 
However , it looks like the behaviour of b35 is correct . this is a regression.

Comments
EVALUATION In sun.lanucher.LauncherHelper: static void signatureDiagnostic(PrintStream ostream, Class<?> clazz) { String classname = clazz.getName(); Method method = null; try { method = clazz.getMethod("main", String[].class); } catch (Exception e) { ostream.println(getLocalizedMessage("java.launcher.cls.error4", classname)); throw new RuntimeException("Main method not found in " + classname); } ... The SecurityException was thrown in the clazz.getMethod(*) but swallowed in the next line.
01-07-2009