Skip to content

Handle default methods in proxied interfaces#250

Draft
headius wants to merge 2 commits into
jnr:masterfrom
headius:default_method_proxy
Draft

Handle default methods in proxied interfaces#250
headius wants to merge 2 commits into
jnr:masterfrom
headius:default_method_proxy

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Jun 14, 2021

It turns out java.lang.Proxy works very poorly in the presence of interface default methods, leading to the issues described in #249. This PR is a prototype of logic to handle such methods using method handles, which works on Java 8-16.

This code is a little heinous, and requires the user (providing the interface) to also have a Lookup object acquired from within that interface, in order to dispatch to the "special" default method bodies.

Java 16 adds a standard way to redispatch to default methods, and the user-side Lookup requirement here is rather heinous, so this may be something we just make a hard error unless we are running on 16.

Fixes #249.

headius added 2 commits June 14, 2021 15:48
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 headius added this to the 2.2.5 milestone Jun 14, 2021
@jnr jnr deleted a comment from Farzin3 Aug 18, 2021
@headius headius modified the milestones: 2.2.5, 2.2.6, 2.2.7 Sep 1, 2021
@headius headius modified the milestones: 2.2.7, 2.2.8 Sep 16, 2021
@headius headius modified the milestones: 2.2.8, 2.2.9 Oct 26, 2021
@headius headius modified the milestones: 2.2.9, 2.2.10 Nov 22, 2021
@headius headius modified the milestones: 2.2.10, 2.2.11 Dec 1, 2021
@headius headius modified the milestones: 2.2.11, 2.2.12 Jan 6, 2022
@headius headius modified the milestones: 2.2.12, 2.2.13 Mar 10, 2022
@headius headius modified the milestones: 2.2.13, 2.2.14 Nov 10, 2022
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 this pull request may close these issues.

Default methods should not be bound

1 participant