Skip to content

can add self var to a object #1871

@316xu

Description

@316xu
        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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions