Here a simple example with the use of bytebuddy is done instrumentation to the constructor of a class at runtime by changing the value of a variable.
Executing the premain and agentmain method
Instrumentation-with-bytebuddy-execute-premain-method
Usuario: pran-u375177
To implement a class, as in this case, elhacker.User
, this class is loaded before our agent implements.
The only way it works is that we load our agent just when it asks for the user's ID.
(1) The User instance is not yet instantiated, so the dialog input is displayed.
(2) Here, the user instance is created.
Point (1)
The class to implement is not yet instantiated, and allows us to load our agent, the User class
is loaded in the main main method, but without instantiating, at that time if we load our agent the instrumentation works.
Point (2)
The User instance has been loaded to the JVM before our agent, so we cannot implement it.
And there, the instrumentation will be applied to the User class.