Skip to content
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

varargs support #123

Open
rukai opened this issue Jul 8, 2024 · 2 comments · May be fixed by #125
Open

varargs support #123

rukai opened this issue Jul 8, 2024 · 2 comments · May be fixed by #125

Comments

@rukai
Copy link
Contributor

rukai commented Jul 8, 2024

It seems that j4rs does not support calling java methods defined with varargs from rust.
I'll take a look into whats missing for this to work, but if you have any ideas I'd love to hear them.

@rukai
Copy link
Contributor Author

rukai commented Jul 8, 2024

The readme lists statics as supporting variadics but that doesnt seem possible since static and non-static methods have the same underlying implementation and neither of them support variadics/varargs.

After looking at the implementation, the fix looks fairly straightforward and I should have a PR up soon.

@rukai
Copy link
Contributor Author

rukai commented Jul 8, 2024

Looking further into it:
There is a test testing that variadics works, so I must be misunderstanding the implementation.
However for some reason a lot of the tests fail when run on my machine:
For example:

running 1 test
test lib_unit_tests::variadic_string_method ... Exception in thread "main" org.astonbitecode.j4rs.errors.InvocationException: While invoking method deploy of Class org.astonbitecode.j4rs.api.deploy.SimpleMavenDeployer
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invoke(JsonInvocationImpl.java:74)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeMethod(JsonInvocationImpl.java:198)
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invoke(JsonInvocationImpl.java:70)
Caused by: java.io.FileNotFoundException: https://repo.maven.apache.org/maven2/io/github/astonbitecode/j4rs-testing/0.21.0-SNAPSHOT/maven-metadata.xml
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:2010)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1615)
	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:223)
	at java.base/java.net.URL.openStream(URL.java:1325)
	at org.astonbitecode.j4rs.api.deploy.SimpleMavenDeployer.getLatestSnapshotName(SimpleMavenDeployer.java:126)
	at org.astonbitecode.j4rs.api.deploy.SimpleMavenDeployer.generateUrlTagret(SimpleMavenDeployer.java:117)
	at org.astonbitecode.j4rs.api.deploy.SimpleMavenDeployer.deploy(SimpleMavenDeployer.java:78)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	... 3 more
FAILED

failures:

---- lib_unit_tests::variadic_string_method stdout ----
ERROR: An Exception was thrown by Java... Please check the logs or the console.
Error: JavaError("org.astonbitecode.j4rs.errors.InstantiationException: Cannot create instance of org.astonbitecode.j4rs.tests.MyTest\n\tat org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:47)\nCaused by: java.lang.ClassNotFoundException: org.astonbitecode.j4rs.tests.MyTest\n\tat java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)\n\tat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)\n\tat java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)\n\tat java.base/java.lang.Class.forName0(Native Method)\n\tat java.base/java.lang.Class.forName(Class.java:529)\n\tat java.base/java.lang.Class.forName(Class.java:508)\n\tat org.astonbitecode.j4rs.utils.Utils.forNameEnhanced(Utils.java:60)\n\tat org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.createInstance(NativeInstantiationImpl.java:96)\n\tat org.astonbitecode.j4rs.api.instantiation.NativeInstantiationImpl.instantiate(NativeInstantiationImpl.java:44)\n")

Test failure resolved by: #124

@rukai rukai linked a pull request Jul 9, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant