ModificationStation / StationAPI

A general use API for Fabric Loader mods on legacy Minecraft versions.
85 stars 19 forks source link

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

Open mineLdiver opened 10 months ago

mineLdiver commented 10 months ago

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 commented 10 months ago

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 commented 9 months ago

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 commented 9 months ago

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