AccessController.doPrivileged and default methods
Sean Mullan
sean.mullan at oracle.com
Fri Jul 7 20:21:05 UTC 2017
On 7/6/17 10:33 AM, Sean Mullan wrote:
> On 7/5/17 4:01 PM, Adam Petcher wrote:
>>
>> Very interesting. The exception originates in the VM, so I added the
>> hotspot-dev list to the discussion. It looks like the VM either can't
>> find the method, or it decides that it's not the right kind of method.
>
> Right. The check that is causing this error is in jvm.cpp [1]:
>
> 1271 if (m.is_null() || !m->is_method() || !m()->is_public() ||
> m()->is_static()) {
> 1272 THROW_MSG_0(vmSymbols::java_lang_InternalError(), "No run method");
> 1273 }
>
> I'll file a bug unless someone has a good explanation for this behavior.
Bug now filed: https://bugs.openjdk.java.net/browse/JDK-8183962
--Sean
>
> Thanks,
> Sean
>
> [1]
> http://hg.openjdk.java.net/jdk9/jdk9/hotspot/file/1ca8f038fceb/src/share/vm/prims/jvm.cpp#l1271
>
>
>
>> On 7/4/2017 7:57 AM, Michael Rasmussen wrote:
>>> 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)
>>
More information about the security-dev
mailing list