Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8290865

`allLineLocations` returns location with offset 2 to the source line numbers

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Ubuntu 20.04
      Java 11, 17.0.3, 18

      A DESCRIPTION OF THE PROBLEM :
      I am using JDI's API to register a breakpoint at a line number and then trying to extract local variables at that point. I use the following code snippet for registering the breakpoint event.
      ```java
      List<Location> locations = event.referenceType().locationsOfLine(lineNumber);
      BreakpointRequest br = erm.createBreakpointRequest(locations.get(0));
      br.setEnabled(true);
      ```
      I execute one of apache commons-lang test (https://github.com/khaes-kth/commons-lang/blob/master/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java#L425) and I intend to set a breakpoint on line 272 of WordUtils.java (https://github.com/khaes-kth/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/text/WordUtils.java#L272). However, I am unable to do that because `event.referenceType().locationsOfLine(272);` returns an empty list which means that there is no debugging information for line 272. I checked the class file and there indeed exists the information for it.

      I tried to debug it further and I found that the calling `Method.allLineLocations` on this method (https://github.com/khaes-kth/commons-lang/blob/19676135286eca93ab4f3980ddb5aa7ffba43bed/src/main/java/org/apache/commons/lang3/text/WordUtils.java#L271) returns a list of locations which are offset by 2. For example, line number 274 is JDI.Location object corresponds to line number 272 of the source file.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Execute `testLANG1397` (https://github.com/khaes-kth/commons-lang/blob/master/src/test/java/org/apache/commons/lang3/text/WordUtilsTest.java#L425).
      2. Set breakpoint on WordUtils.wrap # 272 (https://github.com/khaes-kth/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/text/WordUtils.java#L272)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I should be able to collect local variables for that line since it is an executable line.
      ACTUAL -
      I get no Location object corresponding to that line.

      FREQUENCY : always


            sswsharm swati sharma (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: