Bug 75600 - breakpoint on multi-line statement set in wrong location
Summary: breakpoint on multi-line statement set in wrong location
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 82269 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-10-04 16:43 EDT by Peter Steinfeld CLA
Modified: 2009-08-30 02:41 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Steinfeld CLA 2004-10-04 16:43:07 EDT
Suppose I have the following statement:

        IUpdateSiteAdapter mapped = 
        	ProductRegistry.getUpdatePolicy().getMappedSite(getIdentifier
());

If I double click on the first line, I expect a breakpoint to be set at the 
first effective instruction of the statement.  However, the breakpoint gets set 
on the instruction that corresponds to the assignment -- which is after the 
invocations to "getUpdatePolicy", "getMappedSite", etc.  I can only set a 
breakpoint on the first effective instruction by double-clicking on the second 
line of the statement.

This is very counter-intuitive.  I've never worked with a debugger that works 
like this.
Comment 1 Darin Wright CLA 2004-10-04 16:44:53 EDT

*** This bug has been marked as a duplicate of 75599 ***
Comment 2 Luc Bourlier CLA 2004-10-04 16:54:58 EDT
It's not a dup. In this case, the user add the breakpoint on the first line of
the expression. In bug 75599, the user ask for the breakpoint on line of the
method declaration.
Comment 3 Darin Wright CLA 2004-10-04 22:57:53 EDT
OK, so in bug 75599, the breakpoint should be a method entry breakpoint. 
However, in this bug, my understanding was that the breakpoint appears on the 
line with the "=", which means the breakpoint is on the entire statement 
starting on that line. Execution should stop before the calls to 
getUpdatePolicy() and getMappedSite() - if it is not, then there is a bug.
Comment 4 Darin Wright CLA 2004-10-05 10:16:08 EDT
When I use an example statement as follows, with a breakpoint on the 
assignment line, execution stops at the line, and performing "step into's" I 
see the correct execution order - first a "new Vector(), then "v.toString()", 
then "new StringBuffer(String)"...

boolean a = new Vector().add(
                new StringBuffer(
                        v.toString())
                );

I think this is working as expected.
Comment 5 Darin Wright CLA 2004-10-05 10:18:40 EDT
However, if I use static methods, then I see the same (wrong) behavior:

boolean a = 
            Boolean.getBoolean(
                    new StringBuffer("true").toString());

In this case, execution does not step into the methods. Needs investigation.
Comment 6 Luc Bourlier CLA 2005-01-05 17:59:28 EST
This is not a problem of instance or static method, but a problem with split
assigment to local variable, and split local variable declaration with initializer.

It's more a result of how Java works than anybody's bug.

In Java, a breakpoint is set on a line, and the VM stops its execution just
before executing the code associated to the specified line.
In this case, with the code generated by the Eclipse Java compiler, the first
piece of code associated with the first line of the assigment, is the code which
stores the result of the right-hand expression in the local variable.
This code is executed after the evaluation of the right-hand expression, so when
the breakpoint is hit, the methods "getUpdatePolicy" and "getMappedSite" have
already been executed.

This behavior is only visible if the variable is a local variable. In the other
cases, there will be a piece of code, associated to the first line of the
assigment, to resolve the variable. This code is executed before the evaluation
of the right-hand expression, so when breakpoint would be hit before the
execution of the methods "getUpdatePolicy" and "getMappedSite".

One solution would be to add some bytecode before the evaluation of the
right-hand expression (nop ?), associated to the first line of the evaluation.
But it's ugly.

Moving to JDT/Core to comment/close.
Comment 7 Darin Wright CLA 2005-01-06 08:31:20 EST
*** Bug 82269 has been marked as a duplicate of this bug. ***
Comment 8 Luc Bourlier CLA 2005-01-10 11:39:45 EST
Forgot to add that the problem cannot be reproduced if the class in compiled
with javac. It generates way less precise debug information. Even if a statement
is split on multiple lines, it sets the first line of the statement as the
location for all the code of the statement.
Comment 9 Olivier Thomann CLA 2006-04-19 15:19:30 EDT
Will consider post 3.2
Comment 10 Eclipse Webmaster CLA 2009-08-30 02:41:04 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.