-
Notifications
You must be signed in to change notification settings - Fork 1.7k
jdkProxyObj.getClass().getMethod("xxx")
will throw java.lang.NoSuchMethodException: jdk.proxy4.$Proxy61.xxx()
in the native-image
.
#6079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
native-image
native-image
native-image
native-image
Do you expect the Proxy to be registered automatically? If not, you would need to register it manually. Please see https://www.graalvm.org/22.0/reference-manual/native-image/DynamicProxy/ - Also, please add the GraalVM version, which you used. |
native-image
Method Class.getMethod(methodName)
in the native-image
.
My question is not about dynamic proxy, but about the acquisition of dynamic proxy methods.
|
This will cause the semantic inconsistency of |
Could you maybe add the stacktrace and the config files to this issue? |
I modified the content of this issue. PTAL |
Method Class.getMethod(methodName)
in the native-image
.proxyObj.getClass().getMethod("xxx")
will throw java.lang.NoSuchMethodException: jdk.proxy4.$Proxy61.xxx()
in the native-image
.
proxyObj.getClass().getMethod("xxx")
will throw java.lang.NoSuchMethodException: jdk.proxy4.$Proxy61.xxx()
in the native-image
.jdkProxyObj.getClass().getMethod("xxx")
will throw java.lang.NoSuchMethodException: jdk.proxy4.$Proxy61.xxx()
in the native-image
.
Thank you for sharing this, we'll take a look into it shortly |
This is currently not supported in the metadata. We should allow for proxies to be marked with an interface list: {
"proxy": ["TestInterface"],
"methods": [
{ "name": "foo", "parameterTypes": [] },
{ "name": "bar", "parameterTypes": [] }
]
} Until we introduce that feature, a possible workaround is to use initialization at build time. Rewrite the program in the following way: import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
interface TestInterface {
void foo();
void bar();
}
public class ProxyReflectionExample {
static class ProxyReflectionStatics {
static final TestInterface proxyObj = (TestInterface) Proxy.newProxyInstance(
ProxyReflectionExample.class.getClassLoader(),
new Class[]{TestInterface.class},
(proxy, method, args1) -> {
System.out.println("Method: " + method.getName() + ", Declaring Class: " + method.getDeclaringClass().getName());
return null;
});
}
public static void main(String[] args) throws Exception {
try {
// It will throw `NoSuchMethodException` in `native-image`.
Method method = ProxyReflectionStatics.proxyObj.getClass().getMethod("foo");
System.out.println("Method: " + method.getName() + ", Declaring Class: " + method.getDeclaringClass().getName());
method.invoke(ProxyReflectionStatics.proxyObj);
method = ProxyReflectionStatics.proxyObj.getClass().getMethod("bar");
System.out.println("Method: " + method.getName() + ", Declaring Class: " + method.getDeclaringClass().getName());
method.invoke(ProxyReflectionStatics.proxyObj);
} catch (Throwable t) {
t.printStackTrace();
}
Thread.sleep(10000);
}
} and build it with: native-image ProxyReflectionExample --initialize-at-build-time=ProxyReflectionExample\$ProxyReflectionStatics |
@vjovanov |
Looks like Spring Framework AOP support is impacted by this bug, see this comment for more details. Could this use case be supported out of the box? |
We definitely need to make this a priority. @sdeleuze I am not sure what out of the box means here? |
I mean without additonal hints specified via JSON files if possible. |
That would mean that we have to register all methods of a proxy for reflection. This would lead to bloating of the image which we try to avoid in all places. Is there a difference between this JSON entry and other entries? Why would it be hard to specify the entry in JSON? |
Indeed, we should be careful about the footprint. If we specify metadata explicitly, don't we need all the usual variants (invoke versus introspect, declared versus public versus individual methods)? Should we make introspect the default with the upcoming new reflection mode? If we need all the variants, should they be in Will those new entries be backward compatible with GraalVM 22.3.0 and Jube 2023 releases? |
Fixed by #8822 |
Jdk proxy object can't get method by the
Method Class.getMethod(methodName)
in thenative-image
.jdkProxyObj.getClass().getMethod("xxx")
will throwjava.lang.NoSuchMethodException: jdk.proxy4.$Proxy61.xxx()
in thenative-image
.Example project
https://github.com/wangliang181230/example__oracle_graal_issue-6079
Some code
TestInterface.java
ProxyReflectionExample.java
reflect-config.json
Console output in
JVM
Error log in
native-image
Environment and versions:
Windows 10
graalvm-ce-java17-22.3.1 Windows (amd64)
How can I solve this problem?
The text was updated successfully, but these errors were encountered: