0 Replies Latest reply: Apr 13, 2008 4:38 PM by 843810 RSS

    Weird Random JDI Behaviour when Setting field Values

    843810
      Hello,

      My problem is that i am changing some fields declared in the debuggee code while in debuggee constructor. the problem is that sometimes it is changed successfully and sometimes it is not changed at all.

      For Example if the Debuggee code is as follows:
      begin code
      class NumbersAverage {
           int a,b,c;
           double average;
           
           public NumbersAverage() {
                a=0;
                b=0;
                c=0;
           }
           public void calcAverage() {
                int sum = a+b+c;
                average = sum/3;
           }

           public static void main(String args[]) {
           
                NumbersAverage numAvg = new NumbersAverage();
                numAvg.calcAverage();
           }

      }
      end code

      What i am doing is that At the method that handles ModificationWatchpointEvent if the current method is the constructor i will change the values of a,b and c to something else (say value of 9).

      The Output is as follows:

      * Sometimes sum and average are calculated correctly and the fields are set correctly ( in that case a ,b and c will have the value of 9 and sum will have the value of 27 and average will be 9)
      *Sometimes a,b and c have the value of 9 but sum and average contain the initialization value which is ofcourse 0.
      *Sometimes a,b and c have the value of 9 and sum is 27 but average contain the initialization value which is ofcourse 0.
      *Sometimes they are all 0's

      The Code i am setting with the value is as follows [I Erased The part where i know that it's in the debuggee constructor and identifying which fields to change for sake of simplicity, just the Part of code that uses JDI to set the value]:

      begin code
      fieldWatchEvent(ModificationWatchpointEvent event) {
      try {
           event.object().setValue(event.field(), vm.mirrorOf(9));
           } catch(Exception e){
                e.printStackTrace();
           }
      }

      end code

      And it doesnt Print and Errors ....


      Thanks for your replies.