Bug 21672 - Wrong location for the last 'return' bytecode command
Summary: Wrong location for the last 'return' bytecode command
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-17 16:21 EDT by Luc Bourlier CLA
Modified: 2002-09-20 09:28 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Luc Bourlier CLA 2002-07-17 16:21:10 EDT
If the brace charactere which marks the end of a method body is the first
charactere of its line, the implicit 'return' which is added at the end of the
method bytecode has as location the line above.

An exemple:
1. compile the following compilation unit in Eclipse (just copy/paste, don't
change the indentation):

public class Test {
public static void main(String[] args) {
  boolean v= false;
  if (v)                // <-- breakpoint here
    System.out.println("hi there");
}	
}

2. add the breakpoint and launch the program.
3. when the breakpoint is hit, do a step over.
the 'System.out...' line is highlighted, it looks like the test of the 'if' is
true, even if it's impossible.
4. do resume, nothing is print in the consol. So, as expected, the
'System.out.println("hi there")' is not executed.
5. Edit the compilation unit, add a space charactere just before the brace which
close the method body.
6. Re-compile and re-launch.
7. After hit the breakpoint, do a step over. This time, the correct line is
higtlighted, the line which contains the closing brace.
Comment 1 Philipe Mulet CLA 2002-07-17 16:56:35 EDT
Olivier - I thought we had addressed this scenario using the closing '}' ...
Comment 2 Olivier Thomann CLA 2002-07-17 17:02:01 EDT
I would say the closing parenthesis position is incorrect in this case. I need 
to double-check.
Comment 3 Olivier Thomann CLA 2002-07-17 17:07:59 EDT
In this example, the bodyEnd of the main method is the position of the \n in 
the System.out line. It should be the position of the '}' following this line.
So the free return problem was addressed, but it is assuming a correct position 
for the bodyEnd of the method.
Comment 4 Olivier Thomann CLA 2002-07-17 17:24:35 EDT
Changing this.bodyEnd = endPosition; with this.bodyEnd = endStatementPosition; 
fixes the problem. I need to double-check that there is no side-effect with 
this. endPosition is the character right before the '}'. endStatementPosition 
is the right position. So the bug wasn't with the handling of the free-return, 
but rather with the correctness of the this.bodyEnd position.
Comment 5 Philipe Mulet CLA 2002-07-18 06:04:59 EDT
The body end is supposed to be the last character before the closing '}', so I 
would think it is currently ok (also it has ramifications in syntax recovery, 
so be careful).

I would say that you should rather use the declarationSourcEnd instead.
Comment 6 Olivier Thomann CLA 2002-07-18 09:35:55 EDT
Using the declarationSourceEnd fixed the problem. I will release the code today.
Comment 7 Olivier Thomann CLA 2002-07-18 10:15:33 EDT
Fixed and released in HEAD.
Comment 8 Philipe Mulet CLA 2002-07-23 06:33:33 EDT
Please also backport to R2_0_1 stream
Comment 9 Olivier Thomann CLA 2002-07-23 10:54:51 EDT
backported to 2.0.1.
Comment 10 David Audel CLA 2002-08-19 11:52:09 EDT
Verified.
Comment 11 Jerome Lanneluc CLA 2002-08-19 12:01:11 EDT
Verified
Comment 12 David Audel CLA 2002-09-20 09:28:26 EDT
Verfied in 2.1 M1