Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6856415

Enabling java security manager will make programe thrown wrong exception ( main method not found )

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b102
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      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.

        Issue Links

          Activity

          Hide
          weijun Weijun Wang added a comment -
          BT2: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.
          Show
          weijun Weijun Wang added a comment - BT2: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.

            People

            • Assignee:
              ksrini Kumar Srinivasan
              Reporter:
              jgaosunw Judy Gao (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: