Redefine java.lang classes with ByteBuddy

旧街凉风 提交于 2019-12-06 09:34:40

Yes, Byte Buddy can redefine any class but by default, the bootstrap classes are ignored. You can override this default setting by defining a custom ignore matcher or just removing it alltogether:

AgentBuilder agentBuilder = new AgentBuilder.Default().ignore(none());

I would however strongly advice you against messing with the bootstrap classes and especially with the String class. A lot of code makes strong assumptions about the toString class.

Most JVMs do not allow you to alter the class file format when redefining classes which is why you should enable the .disableClassFormatChanges() option. Doing so, you cannot longer add methods or fields which is when you should look into using the Advice class instead of the standard interceptors.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!