Bug 259129 - [compiler] Fup of bug 258950, wrong line number attribute for cascading method invocations
Summary: [compiler] Fup of bug 258950, wrong line number attribute for cascading metho...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-17 11:14 EST by Olivier Thomann CLA
Modified: 2009-01-27 05:18 EST (History)
1 user (show)

See Also:


Attachments
Proposed fix (1.07 KB, patch)
2008-12-17 11:16 EST, Olivier Thomann CLA
no flags Details | Diff
Same patch with regression test (6.02 KB, patch)
2008-12-17 11:20 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2008-12-17 11:14:51 EST
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.
Comment 1 Olivier Thomann CLA 2008-12-17 11:16:08 EST
Created attachment 120714 [details]
Proposed fix
Comment 2 Olivier Thomann CLA 2008-12-17 11:20:38 EST
Created attachment 120716 [details]
Same patch with regression test
Comment 3 Philipe Mulet CLA 2008-12-17 12:35:34 EST
+1
Comment 4 Olivier Thomann CLA 2008-12-17 12:39:05 EST
Released for 3.5M5.
Regression test added in org.eclipse.jdt.core.tests.compiler.regression.DebugAttributeTest#test003
Comment 5 Frederic Fusier CLA 2009-01-27 05:17:51 EST
Verified for 3.5M4 using build I20090127-0100
Comment 6 Frederic Fusier CLA 2009-01-27 05:18:46 EST
(In reply to comment #5)
> Verified for 3.5M4 using build I20090127-0100
> 
I meant ... for 3.5M5...!