Open cobizobi opened 2 years ago
Which java version are you using? I believe something is broken after java 13. @Hervian can you have a look at this? I am facing the same issue. It seems that they did some change about module checking and the function hasFullPrivilegeAccess returns false
On my use case, I was loading an external class with class loader and then I was using LamdaFactory in order to be able to call a static method from the external class, from within my executable. Basically the user could write java code on an external file, then using the compiler tools my app would compile the java code into a class, and the load it and execute.
I found a solution on my problem that worked both in java 8 and up to java 20 without any modifications.
Basically I do this when using the class loader:
loader = new URLClassLoader(new URL[] {url}) { { byte[] code = gimmeLookupClassDef(); defineClass("GimmeLookup", code, 0, code.length); } };
lookup = (MethodHandles.Lookup) loader.loadClass("GimmeLookup").getField("lookup").get(null);
and GimmeLookup is:
static byte[] gimmeLookupClassDef() {
return ( "\u00CA\u00FE\u00BA\u00BE\0\0\0001\0\21\1\0\13GimmeLookup\7\0\1\1\0\20"
+"java/lang/Object\7\0\3\1\0\10
Then I pass this lookup inside the create function of LambdaFactory.
these: MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(method.getDeclaringClass(), MethodHandles.lookup()); or lookup = lookup.in(method.getDeclaringClass());
are no longer needed with that approach.
@Hervian I dont know if you are using a class loader, but it might worth taking a look. If it is the case that this is something else all together, then I apologize for the confusion.
Hi, currently I run in a LambdaConversionException when I do the following (
class
is a Class Object extracted per reflection, not like MyClass.class):copy = clazz.getDeclaredMethod("method");
lambda_copy = LambdaFactory.create(copy);
The exception is:
I don't know if this is a bug, so I am also happy about any suggestions on this. Thanks!