can add self var to a object
new AgentBuilder.Default()
.type(ElementMatchers.is(HikariDataSource.class))
.transform(new Transformer() {
@Override
public Builder<?> transform(Builder<?> builder, TypeDescription typeDescription,
ClassLoader classLoader, JavaModule module, ProtectionDomain protectionDomain) {
return builder
.defineField("ds1", HikariDataSource.class, Visibility.PUBLIC)
.defineField("proxy", Boolean.class, Visibility.PUBLIC)
.defineField("current", Integer.class, Visibility.PUBLIC);
}
})
.with(AgentBuilder.Listener.StreamWriting.toSystemError())
.with(AgentBuilder.InstallationListener.StreamWriting.toSystemError())
.with(RedefinitionStrategy.RETRANSFORMATION)
.installOn(inst);
when run it does not work, and log:
[Byte Buddy] DISCOVERY com.zaxxer.hikari.HikariDataSource [sun.misc.Launcher$AppClassLoader@18b4aac2, null, Thread[main,5,main], loaded=true] [Byte Buddy] TRANSFORM com.zaxxer.hikari.HikariDataSource [sun.misc.Launcher$AppClassLoader@18b4aac2, null, Thread[main,5,main], loaded=true] [Byte Buddy] COMPLETE com.zaxxer.hikari.HikariDataSource [sun.misc.Launcher$AppClassLoader@18b4aac2, null, Thread[main,5,main], loaded=true]
when remove the ds1 field, all works fine
how to reload the loaded class, thanks
You should use a TypePool to describe types without loading. Avoid referencing HikariDataSource and rather match the type using "named". Then use TargetType.class instead of HikariDataSource.class. This way you can even manage without a type pool.