1 Reply Latest reply on Jun 21, 2014 6:46 PM by Staffan Larsen-Oracle

    How to set a Object value by JDI


      How to set a Object value using JDI?

      For example:


      class User{

        private String name;

        private String id;


      set and get method;




      public static void main(String[] args) throws Exception {



              VirtualMachineManager vmm = Bootstrap.virtualMachineManager();

              List<AttachingConnector> connectors = vmm.attachingConnectors();

              SocketAttachingConnector sac = null;

              for (AttachingConnector ac : connectors) {

                  if (ac instanceof SocketAttachingConnector) {

                      sac = (SocketAttachingConnector) ac;






              if (sac == null) {

                  System.out.println("JDI error");




              Map<String, Connector.Argument> arguments = sac.defaultArguments();

              Connector.Argument hostArg = arguments.get("hostname");

              Connector.Argument portArg = arguments.get("port");







              vmMachine = sac.attach(arguments);



              List<ReferenceType> classesByName = vmMachine.classesByName(CLSNAME);

              if (classesByName == null || classesByName.size() == 0) {

                  System.out.println("No class found");





              ReferenceType rt = classesByName.get(0);

              List<Method> methodsByName = rt.methodsByName(METHODNAME);

              if (methodsByName == null || methodsByName.size() == 0) {

                  System.out.println("No method found");



              Method method = methodsByName.get(0);






      I will connect to server and monitor the remote server JVM , There is a object of User, I want to change its value by the Java Debugger Interface by client.

      so how to set its value by the client, and I can not got the User bean at client.


      I know the basic type filed value changed as follows:


      Value newValue = vmMachine.mirrorOf("change var value");// this field is a string.

      stackFrame.thisObject().setValue(field, newValue);


      But a Object , how can I change its value.


      Thanks Advanced.