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

Default methods should not be bound #249

Open
headius opened this issue Jun 14, 2021 · 0 comments · May be fixed by #250
Open

Default methods should not be bound #249

headius opened this issue Jun 14, 2021 · 0 comments · May be fixed by #250

Comments

@headius
Copy link
Member

headius commented Jun 14, 2021

In jruby/jruby#6714 we discovered that jnr-ffi is attempting to bind a getsockoptInt method to the same named-C function, which of course fails.

The problem here is due to JRuby's BasicSocket using an interface for jnr-ffi that has default methods (utility wrappers around the other methods) which are not intended to be bound to a native endpoint. The java.lang.Proxy logic in Java 8-15 provides no way to invoke the default method, so we proceed to attempt to bind it as a native call.

Unfortunately the fixes for this are pretty heinous. This SO post seems to indicate that there is no clean way to fix it until Java 16. The only option for us in Java 8 would be to rework how the interface proxy gets initialized, passing in a Lookup that can access and call the default method.

https://stackoverflow.com/questions/26206614/java8-dynamic-proxy-and-default-methods

For now we will remove the default methods in JRuby, but this needs a proper fix in jnr-ffi.

headius added a commit to headius/jnr-ffi that referenced this issue Jun 14, 2021
Default methods on interfaces fed to java.lang.Proxy cannot be
invoked without using method handles, which requires a Lookup with
private access (acquired within the interface class). This commit
adds a load path that propagates such a Lookup through to the
eventual Proxy instance, allowing it to skip binding default
methods to their (nonexistent) native function, instead calling
the provided default method body.

Fixes jnr#249.
headius added a commit to headius/jnr-ffi that referenced this issue Jun 14, 2021
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