Simple Dynamic attach not found
See original GitHub issueHi Rafael,
I have the same 3 classes last https://github.com/raphw/byte-buddy/issues/643 very simple, but this time, I use the agentmain due to the jframe already in full execution.
I am using jdk 8, with the tools.jar in the classpath
public static void agentmain(final String args, Instrumentation inst) {
System.out.print("agent main");
new AgentBuilder.Default()
.ignore(ElementMatchers.none())
.disableClassFormatChanges()
.with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.with(AgentBuilder.Listener.StreamWriting.toSystemOut())
.type((ElementMatchers.nameContains("Usuario")))
.transform((builder, typeDescription, classLoader, module) ->
builder.visit(Advice.to(MoreLifeAdvice.class)
.on(ElementMatchers.isConstructor()))
)
.installOn(inst);
}
MoreLifeAdvice
public class MoreLifeAdvice {
@Advice.OnMethodExit
static void giveMeMoreLife(@Advice.FieldValue(value = "life", readOnly = false) int life)
throws Exception {
System.out.println("New life set to 1000");
life = 1000;
}
}
Launcher
public static void main( String[] args ) {
final Path path = getFile(null,JFileChooser.FILES_ONLY);
ByteBuddyAgent.attach(path.toFile(),"pid");
}
No exception is thrown And the field x is not modified

Yesterday I was able to verify that the Advice is not executed
Thanks for the help provided.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Fixing Bugs in Running Java Code with Dynamic Attach
Using Java agents and the dynamic attach and instrumentation APIs it is possible to fix bugs in running Java programs.
Read more >Dynamically attaching a Java agent not working - Stack Overflow
Just inspect the output directory, and you will see it. Simply add the missing class file to the JAR and be happy: runCommand("jar...
Read more >Using JConsole - Java SE Monitoring and Management Guide
Applications which support dynamic attach do not require the management agent to be started by specifying the com.sun.management.jmxremote or ...
Read more >Attach a Database - SQL Server - Microsoft Learn
Learn how to attach a database in SQL Server by using SQL Server Management Studio or Transact-SQL. Use this feature to copy, move, ......
Read more >Unknown thread dumps found in mule_ee.log
If we see thread dumps in mule_ee.log while no one purposely triggers it, it might be the dynamic attach is failing.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

My lord, how class of bytebuddy API , helps me?
I’m going crazy now. Damn lmao.
I should be use bytebuddy API right?
You would need to check when your constructor is called and when your agent is attached. If the latter happens before the former, the field value will mot have changed.