2 Replies Latest reply: May 9, 2008 8:50 PM by 843810 RSS

    Possible JDI bug When Recursion

    843810
      Hello ,

      I am tracing the following code of Binary Search

      begin code
           public boolean BSearch(int low, int high) {
                int mid = 0;
                if (low > high)
                     return false;
                else
                {
                     mid = (new Double(Math.floor((low+high)/2.0))).intValue();
                     if (x == S[mid])
                          return true;
                     else {
                          if (x < S[mid])
                               return BSearch(low, mid - 1);
                          else
                               return BSearch(mid + 1, high);
                     }
                }
           }
      end code

      The Problem is that variables low and high arent updated correctly, When returning from the the method BSearch() sometimes a stepEvent() is fired for modification of variables low,high or mid. and sometimes no StepEvent() is fired.

      To be more specific, When returning from the method BSearch to the same line number no Step Event is fired , but if the previous line number is different then stepevent is fired correctly.

      For Example:
      if BSearch(mid + 1, high); is executed 4 times , then returned 4 times , it will always return to the same line number which is BSearch(mid + 1, high); line number.
      But if BSearch(mid + 1, high); is executed then BSearch(low, mid - 1); is executed then BSearch(mid + 1, high); it will return to different line numbers and step event will be fired.

      Seems that Step Event is fired only if the line number currently executing is modified regardless of the current stack frame.

      Thanx for your comments

      Edited by: 3ashmawy on May 3, 2008 5:43 PM