transformer
transformer copied to clipboard
Intercept Class.forName and similar calls to perform package renaming dynamically
The transformer can be made to handle renaming all static references, but references to types in a String, which can be assembled at runtime, will need to be handles at runtime.
The tool can mutate the call sites to methods like Class.forName, ClassLoader.loadClass, etc. to call a supplied interceptor method which can inspect the assembled string and perform any renames before calling the method from the original call site.
[From https://github.com/bjhargrave/transformer-poc/issues/2]
My thinking is that this can be done with constant pool manipulation. The constant pool methodRef entry for Class.forName is altered to be a methodRef to a method (in some transformer helper class added to the artifact) which does the class name string argument transformation before calling the Class.forName method and returning the result. Similar constant pool entry alterations would be done for other methodRefs to ClassLoader.loadClass, etc.
This avoids having to process and modify method bodies in all the methods' CodeAttributes.
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. If you feel this is something you could contribute, please have a look at our Contributor Guide. Thank you for your contribution.
This issue has been automatically closed due to inactivity. If you can reproduce this or if you have a good use case for this feature, please feel free to reopen the issue with steps to reproduce, a quick explanation of your use case or a high-quality pull request.