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

JVM_DoPrivileged does not find run method in default methods

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 10
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b21
    • CPU:
      generic
    • OS:
      generic

      Description

      JVM_DoPrivileged calls run()Ljava/lang/Object;
      It searches in the "action" class and superclasses for the method, but
      does not search for inherited default methods.

      Bug reported by Michael Rasmussen@zeroturnaround.com on security-dev@openjdk.java.net and forwarded by Sean Mullan:

      Hi

      I was playing around with having an easy way to have doPrivileged call
      void methods via lambdas/method references, and noticed that if you
      use AccessController.doPrivileged(PrivilegedAction), and the run
      method is implemented as a default method, then you get the following
      exception: java.lang.InternalError: No run method

      I failed finding anywhere in the documentation stating this should not
      be supported, or a bug report about it, so writing/asking here.

      See example code below

      Kind regards
      Michael Rasmussen


      //----

      package com.test;

      import java.security.AccessController;
      import java.security.PrivilegedAction;

      public class Test {
       interface VoidPrivilegedAction extends PrivilegedAction<Void> {
         void perform();

         @Override
         default Void run() {
           perform();
           return null;
         }
       }

       static void doPrivileged(VoidPrivilegedAction act) {
         AccessController.doPrivileged(act);
       }

       public static void main(String[] args) throws Exception {
         doPrivileged(() -> System.out.println(System.getProperty("java.home")));
       }
      }

      //----

      Exception in thread "main" java.lang.InternalError: No run method
      at java.security.AccessController.doPrivileged(Native Method)
      at com.test.Test.doPrivileged(Test.java:18)
      at com.test.Test.main(Test.java:22)

        Attachments

          Activity

            People

            Assignee:
            hseigel Harold Seigel
            Reporter:
            acorn Karen Kinnear (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: