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

Access to default methods in @JImplements #1182

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Thrameos
Copy link
Contributor

Default methods are a pain because the proxy to interfaces always redirects and there is no "normal" method of accessing such a method via reflection. The PR uses MethodHandles to perform the redirect. It is no clear if this works in Java 8 though as some of the comments regarding this method indicate that it may be a Java 9 feature. I added test cases to see if this is true. If it is only a Java 9 feature we can try to implement a mixed mode jar file, but that will get more complicated.

Fixes #1181

@Thrameos
Copy link
Contributor Author

Will be hard to get this to work as the jar file must be loaded into the base classloader. It may be doable, but will require serious effort.

@marscher
Copy link
Member

marscher commented May 7, 2024

sorry I cannot estimate if it'd be worth the effort? How common are these "default methods"?

@Thrameos
Copy link
Contributor Author

Thrameos commented May 7, 2024

Default methods are a newer feature of Java in which the programmers adds some functionality to an interface which will automatically be available to the implemented classes. They are common in newer code, but most of the Java library classes currently don't use them. They are difficult to access because they didn't exist when JNI was written so there is no "call the default" method and the proxy system works against them. The issue here is that the newer java security methods prevent calling code from arbitrary modules, and our jar is not located in a position of any privilege as we are not in the boot loader.

About the only way I can make this happen would be to make my own Jar loader which uses the JNI special under the table class definition method which in theory would get the JPype into a lower level. However, JNI doesn't really have any support for modules or module definition so I have no idea if I can actually get to the level required to make this type of access. Making a jar side loader would require access to gzip and tar access. There may be severe technical issues if I need to load the class files in a particular order.

One can expect that many libraries will have default method if they use interfaces at some point. Thus there is some value, but it is a large lift (and given I am underwater until July it won't happen soon.)

@marscher
Copy link
Member

marscher commented May 8, 2024

Bypassing JVMs security mechanisms does not seem right. If these extended Interfaces do not posses a mechanism in JNI, we should request them upstream. It does not make any sense for them to be inacessible, right?

Why are default methods not already handled by the MRO, e.g. calling the parents implementation? Actually it should, should it not?
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8033126

@Thrameos
Copy link
Contributor Author

Thrameos commented May 8, 2024 via email

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.

Clarity in Implementation of interfaces with default methods
2 participants