Bug 136688 - [compiler] fup on bug 86813: step into switch behaves unexpectedly
Summary: [compiler] fup on bug 86813: step into switch behaves unexpectedly
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-13 13:00 EDT by Maxime Daniel CLA
Modified: 2009-08-30 02:17 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix (1.52 KB, patch)
2006-04-19 15:26 EDT, Olivier Thomann CLA
no flags Details | Diff
Better patch (3.46 KB, patch)
2006-04-19 16:16 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression test (894 bytes, patch)
2006-04-19 19:13 EDT, 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 Maxime Daniel CLA 2006-04-13 13:00:17 EDT
Build id: I20060413-0010.
The two (faulty) test cases suggested in comment #6 of bug 86813 can be reproduced. They were contributed by Stefano Rocca and are copied here for convenience.

TEST A

public class Bug_86813a {
        public static void main(String[] args) {
                int x = -1; // 1. breakpoint here
                try {
                        int i = 4;
                        switch (i) {
                        case 1:
                                x = 3;
                                break;
                        case 2:
                                x = 4; // 2. jumps here
                                break; // does not step here
                        default:
                        }
                } catch (Exception e) {
                }
                System.out.println(x); // 3. jumps here
                System.exit(0);
        }
}

The empty default statement does not resolve the problem.

TEST B

public class Bug_86813b {
        public static void main(String[] args) {
                int x = -1; // 1. breakpoint here
                try {
                        int i = 4;
                        switch (i) {
                        case 1:
                                x = 3;
                                break;
                        case 2:
                                x = 4; 
                                break; // 2. jumps here
                        default:
                                break; // does not step here
                        }
                } catch (Exception e) {
                }

                System.out.println(x); // 3. jumps here
                System.exit(0);
        }
}

The default statement is apparently ignored
Comment 1 Olivier Thomann CLA 2006-04-13 15:41:21 EDT
The problem comes from the optimized goto to the next bytecode.
Removing the goto also removes the entry in the line table.
Comment 2 Olivier Thomann CLA 2006-04-19 15:26:18 EDT
Created attachment 38975 [details]
Proposed fix

Maxime,

Could you please try this patch? I believe it improves the debug experience.
Comment 3 Olivier Thomann CLA 2006-04-19 15:26:36 EDT
Philippe,

RC2 candidate ?
Comment 4 Olivier Thomann CLA 2006-04-19 16:16:44 EDT
Created attachment 38980 [details]
Better patch
Comment 5 Olivier Thomann CLA 2006-04-19 19:13:57 EDT
Created attachment 38993 [details]
Regression test

Update the test case for bug 86813 (SwitchTest.test12)
Comment 6 Maxime Daniel CLA 2006-04-20 01:29:01 EDT
(In reply to comment #2)
> Created an attachment (id=38975) [edit]
> Proposed fix
> 
> Maxime,
> 
> Could you please try this patch? I believe it improves the debug experience.
> 
Trying with your latest patch, I get something better, but still a bit odd.
Taking TEST A case, I jump from the switch line to the second break line (instead of the default line). Is it the behavior you get ?
Comment 7 Philipe Mulet CLA 2006-04-20 07:34:37 EDT
I am not seeing how a change in ForeachStatement (see patch) is indicated here...
I have the feel all introduced branch bytecodes (jump to natural try exit, jump over if-else, etc...) are going to exhibit same behavior. Growing the last entry is simply not the answer in case it is not on the execution path (like here with switch scenario).
Comment 8 Philipe Mulet CLA 2006-04-20 07:44:41 EDT
Same issue with enclosing IF:
public class X {
        public static void main(String[] args) {
                int x = -1; // 1. breakpoint here
                if (args != null) {
                        int i = 4;
                        switch (i) {
                        case 1:
                                x = 3;
                                break;
                        case 2:
                                x = 4; // 2. jumps here
                                break; // does not step here
                        default:
                        }
                } else {
                	x = 5;
                }
                System.out.println(x); // 3. jumps here
        }
}
Comment 9 Philipe Mulet CLA 2006-04-20 09:13:27 EDT
I'd be enclined to defer post 3.2 (i.e. not worse than it was in 3.1, and a bit late to worry about)
Comment 10 Olivier Thomann CLA 2006-04-20 09:30:05 EDT
> Trying with your latest patch, I get something better, but still a bit odd.
> Taking TEST A case, I jump from the switch line to the second break line
> (instead of the default line). Is it the behavior you get ?
In the first case, the line with the default doesn't generate anything so the previous break statement is the best option.
Comment 11 Olivier Thomann CLA 2006-04-20 09:45:04 EDT
(In reply to comment #7)
> I am not seeing how a change in ForeachStatement (see patch) is indicated
> here...
This change is to be sure that no entry is added when no code has been generated since last entry. It prevents a method call.

> I have the feel all introduced branch bytecodes (jump to natural try exit, jump
> over if-else, etc...) are going to exhibit same behavior. Growing the last
> entry is simply not the answer in case it is not on the execution path (like
> here with switch scenario).
I don't grow the last entry. I simply readjust its line number if required.
Comment 12 Olivier Thomann CLA 2006-04-20 09:45:19 EDT
Closing as LATER.
Comment 13 Olivier Thomann CLA 2006-04-20 09:50:33 EDT
(In reply to comment #8)
> Same issue with enclosing IF:
The patch also handles this case.
Since the default doesn't generate any code, the previous break is used. If there is no break, we then end up with the same line as today.
We might want to associate the jump to the source end of the switch statement.
Comment 14 Denis Roy CLA 2009-08-30 02:17:27 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.