Community
Participate
Working Groups
With the following test case: import java.util.List; import java.util.ArrayList; import java.util.Iterator; public class X { public static void main(String[] args) { List l = new ArrayList(); List l2 = new ArrayList(); l.add(new X()); for (Iterator iterator = l.iterator(); iterator.hasNext() ;) { l2.add(((X) iterator.next()).toString() .substring(3)); } for (Iterator iterator = l2.iterator(); iterator.hasNext() ;) { System.out.println(iterator.next()); } } public String toString() { return "NO_SUCCESS"; } } we produce the following code generation: 36 astore_3 [iterator] 37 goto 63 40 aload_2 [l2] 41 aload_3 [iterator] 42 invokeinterface Iterator.next() : Object [30] [nargs: 1] 47 checkcast X [1] 50 invokevirtual X.toString() : String [36] 53 iconst_3 54 invokevirtual String.substring(int) : String [40] 57 invokeinterface List.add(Object) : boolean [20] [nargs: 2] 62 pop 63 aload_3 [iterator] 64 invokeinterface Iterator.hasNext() : boolean [46] [nargs: 1] [pc: 0, line: 6] [pc: 8, line: 7] [pc: 16, line: 8] [pc: 30, line: 9] [pc: 40, line: 10] [pc: 41, line: 11] [pc: 57, line: 10] [pc: 63, line: 9] [pc: 72, line: 13] [pc: 82, line: 14] [pc: 94, line: 13] [pc: 103, line: 16] You can see that the entry for pc 41 is boggus. It doesn't correspond to the right line of code. It should be: [pc: 40, line: 10] [pc: 53, line: 11] [pc: 57, line: 10] This is causing some grief to the code to retrieve the right line of source for API/Tools (see bug 258950). The problem comes from the last entry in the line number attribute that we add using the pc that starts the whole cascading method invocation. We should update the pc to the position that is located before we invoke the last method invocation.
Created attachment 120714 [details] Proposed fix
Created attachment 120716 [details] Same patch with regression test
+1
Released for 3.5M5. Regression test added in org.eclipse.jdt.core.tests.compiler.regression.DebugAttributeTest#test003
Verified for 3.5M4 using build I20090127-0100
(In reply to comment #5) > Verified for 3.5M4 using build I20090127-0100 > I meant ... for 3.5M5...!