lundi 30 octobre 2023

How to inject a method into a class at runtime without ASM?

In past versions of the bytecode manipulation framework Mixin, there was a method called prepareConfigs(MixinEnvironment). A nonstandard, but very commonly-used, way to bootstrap Mixins at a certain phase of the lifecycle was to access and call that method using Reflection.

In later versions of the framework, that method's signature has been changed to prepareConfigs(MixinEnvironment, Extensions), causing the Reflection-based usages to break.

The owner of the library has made it clear that breaking this was intentional and will not allow a fix. However, even though it was bad practice to use that strategy, the usage was common enough that end-users are unable to use many apps that relied on the framework.

I would like to make a compatibility patch that adds the old method back to the class to stop the crashes. Problem is, this requires injecting a method into a class that is restricted from being transformed by ASM.

The only requirement is that the method does not throw a NoSuchMethodException when accessed via reflection, since I'm easily able to implement their intended behavior somewhere else. It doesn't actually need to do anything, it just needs to stop the exception from being thrown.

I've heard people offhand-mention a way to declare class members that can only be accessed by Reflection, but I couldn't find any details on it.

Is there a way to do what I need without ASM?





Aucun commentaire:

Enregistrer un commentaire