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

JEP 416 causes StAPI to crash on Java 18 onward #87

Open
mineLdiver opened this issue Dec 10, 2023 · 3 comments
Open

JEP 416 causes StAPI to crash on Java 18 onward #87

mineLdiver opened this issue Dec 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@mineLdiver
Copy link
Member

https://openjdk.org/jeps/416

Since all reflection is refactored to use method handles, StAPI's reflection trick to replace final fields no longer works.
This can probably be fixed by using Unsafe instead.

@mineLdiver mineLdiver added the bug Something isn't working label Dec 10, 2023
@mineLdiver
Copy link
Member Author

A better approach would probably be analysing the entrypoint classes with SpASM and replacing calls to Null.get() with initialization of the objects required by the class.

However, this won't work with @Entrypoint.Instance static final fields, as the instance is created by Fabric way after the class has initialized. @Entrypoint.Namespace fields won't work either, as we have no way of getting the mod container from a class during its transformation by SpASM.

@Geolykt
Copy link

Geolykt commented Jan 30, 2024

Since all reflection is refactored to use method handles, StAPI's reflection trick to replace final fields no longer works.
This can probably be fixed by using Unsafe instead.

Using Unsafe as a replacement is nonsense too thanks to JEP 8323072.

@mineLdiver
Copy link
Member Author

Well, can still resort to SpASM - by either removing the final modifier from the field's bytecode itself, or generating an initializer.

There's also a cursed approach that involves generating a constructor with SpASM and invoking that through hacky means on an already instantiated object to overwrite values in instance final fields, but that might have already been patched in later Java versions.
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants