Bug 164657 - [compiler] Wrong line is showed during debug
Summary: [compiler] Wrong line is showed during debug
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-11-15 11:27 EST by David Audel CLA
Modified: 2006-12-12 12:35 EST (History)
0 users

See Also:


Attachments
Proposed fix (2.76 KB, patch)
2006-11-19 11:29 EST, Olivier Thomann CLA
no flags Details | Diff
Regression tests (4.67 KB, patch)
2006-11-19 11:29 EST, Olivier Thomann CLA
no flags Details | Diff
New patch (4.66 KB, patch)
2006-11-20 14:25 EST, Olivier Thomann CLA
no flags Details | Diff
Updated regression tests (4.89 KB, patch)
2006-11-20 14:26 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 David Audel CLA 2006-11-15 11:27:20 EST
Sorry i don't have a simple test case to reproduce the problem

1) install build I20061114-1636
2) launch it
3) checkout org.eclipse.jdt.core v723
4) open org.eclipse.jdt.internal.compiler.ast.WhileStatement
5) add a breakpoint at the beginning of Parser#consumeStatementWhile()
6) add a breakpoint at the beginning of AssistParser#consumeToken(int)
7) disable all your breakpoints
8) launch the Eclipse of your worskspace in debug mode
9) create this compilation unit

public class Test
{
    public static class AnyClass
    {
        public static void callMe()
        {
            System.out.println("whatever");
        }
    }

    public void method1()
    {
//        LOOP_WHILE:
        while (true)
        {
            if (0 > (10))
            {
//                break LOOP_WHILE;
            }
        }
        AnyClass.callMe(); //code completion fails here
    }
}

10) enable the breakpoint at Parser#consumeStatementWhile()
11) place the cursor inside 'callMe' invocation and code assist (ctrl+space)
you hit the breakpoint at Parser#consumeStatementWhile()
12) enable the breakpoint at AssistParser#consumeToken(int)
13) do resume (F9)
you hit the breakpoint at AssistParser#consumeToken(int)
14) do step over (F6) then you reach line 686 :"if(isFirst) {"
15) do step over (F6) then you reach line 692 :"if (isInsideMethod() || isInsideFieldInitialization() || isInsideAttributeValue()) {"
16) do step over (F6) then you reach line 693 :"switch (token) {"
17) do step over (F6) then you reach line 709 :"this.pushOnElementStack(K_SELECTOR, this.identifierPtr);"

You should not reach the line 709, the value of 'token' is the value of TokenNameIdentifier and the only case of the switch contains TokenNameLPAREN.
The position of the last step over is wrong. The code of line 709 doesn't seem to be executed but the debugger show this line.
Comment 1 Olivier Thomann CLA 2006-11-17 17:13:52 EST
Smaller test case:
public class X {
	private static final int CONST_1 = 1;

	private static boolean foo() {
		return true;
	}
	public static void main(String[] args) {
		int token = 5;
		int previousToken = 7;
		if (foo()) {
			switch (token) {
				case 5 :
					switch (previousToken) {
						case CONST_1:
							if(token > -1) {
								bar(7);
							}
							break;
					}
					break;
			}
		} else {
			bar(8);
		}
	}
	
	private static void bar(int i) {
		if (i == 7) {
			System.out.println("FAILED"); //$NON-NLS-1$
		}
	}
}

Stepping inside main goes to bar(7) even if this is never executed.
Comment 2 Olivier Thomann CLA 2006-11-19 11:29:00 EST
Created attachment 54133 [details]
Proposed fix

David, could you please try this patch?
Comment 3 Olivier Thomann CLA 2006-11-19 11:29:31 EST
Created attachment 54134 [details]
Regression tests
Comment 4 David Audel CLA 2006-11-20 04:02:53 EST
I tried the patch and i still reproduce the problem.
Comment 5 Olivier Thomann CLA 2006-11-20 10:11:48 EST
Are you sure you rebuilt the project ?
Comment 6 David Audel CLA 2006-11-20 11:53:02 EST
I forgot to rebuild the project. I retry your patch.
Comment 7 David Audel CLA 2006-11-20 12:01:56 EST
The behavior have change but there is still a bug.
Now the step 17 of my test case is

17) do step over (F6) then you reach line 713: "break;"
instead of 
17) do step over (F6) then you reach line 709: "this.pushOnElementStack(K_SELECTOR, this.identifierPtr);"

The correct line should be 724.
Comment 8 David Audel CLA 2006-11-20 12:21:25 EST
I can reproduce the problem by replacing "int token = 5;" by "int token = 6;" in your test case.
Comment 9 Olivier Thomann CLA 2006-11-20 14:10:55 EST
(In reply to comment #7)
> The correct line should be 724.
There is no way I can get line 724. I think line 714 would be acceptable.
Comment 10 Olivier Thomann CLA 2006-11-20 14:25:44 EST
Created attachment 54196 [details]
New patch
Comment 11 Olivier Thomann CLA 2006-11-20 14:26:02 EST
Created attachment 54197 [details]
Updated regression tests
Comment 12 Olivier Thomann CLA 2006-11-20 14:26:27 EST
David, could you please confirm that this works better?
I'll try it on my side as well.
Comment 13 Olivier Thomann CLA 2006-11-20 14:41:51 EST
Looks much better to me.
Comment 14 David Audel CLA 2006-11-21 03:52:01 EST
It works as you describe. The line 724 would be better but 714 is acceptable.
Comment 15 Olivier Thomann CLA 2006-11-21 10:48:03 EST
Released for 3.3M4.
Comment 16 David Audel CLA 2006-12-12 12:35:21 EST
Verified for 3.3M4 with I20061212-0010.