I have a small problem and I wonder how others solve this. Assuming I have
foo.bar()
with the static type of foo being Object. Let us assume there is a
public class Base which provides a public method bar and there is a
class Foo$Foo extending Base, overriding bar, but this class is private.
foo be an instance of Foo$Foo.
If I now follow the usual pattern of Groovy method selection, then this
will give me of course Foo#bar. But if I want to use that I get a
"symbolic reference class is not public"
I may have no control over this class, so I don't see how I could get a
LOOKUP object... how am I supposed to call this method? Should I really
fall back to reflection for this?
bye blackdrag
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
You can always bypass the security by creating a j.l.r.Method,
call setAccessible() on it and then use lookup.unreflect().
cheers,
R�mi
ah! ok... thanks.
hmm... I seemed to be happy too early... it does not work
it works !
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
public class SecBypass {
public static class Base {
public void foo() {
System.out.println("Base::foo");
}
}
static class Sub extends Base {
public void foo() {
System.out.println("Sub::foo");
}
}
public static void main(String[] args) throws Throwable {
Base base = new Sub();
//MethodHandle mh =
MethodHandles.publicLookup().findVirtual(Sub.class, "foo",
MethodType.methodType(void.class));
// don't work
Method method = Sub.class.getDeclaredMethod("foo");
method.setAccessible(true);
MethodHandle mh = MethodHandles.publicLookup().unreflect(method);
// ok
mh.invoke(base);
}
}
>
> bye blackdrag
>
cheers,
R�mi
sorry, I take it back. It was too late already and I didn't see that the
error and the taken path in the code are totally unrelated.
On Saturday, January 7, 2012 at 11:56 PM, Rémi Forax wrote:
On 01/07/2012 11:43 PM, Jochen Theodorou wrote:
Am 07.01.2012 23:21, schrieb Jochen Theodorou:
Rémi--You received this message because you are subscribed to the Google Groups "JVM Languages" group.To post to this group, send email to jvm-la...@googlegroups.com.To unsubscribe from this group, send email to jvm-language...@googlegroups.com.For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.
Hi,
Is there a performance penalty in using a method handle obtained using unreflect() vs findVirtual()?
This is not clear from the docs.