Bug 11217 - is double "; " on a return statement an error?
Summary: is double "; " on a return statement an error?
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 minor (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 72467 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-03-12 17:30 EST by Rodrigo Peretti CLA
Modified: 2004-08-23 18:57 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 Rodrigo Peretti CLA 2002-03-12 17:30:04 EST
build 20020312

The following method might meet the java spec but the error message seems 
strange at first and only makes sense later.

Object getObject() {
  Object myObject = new Object();;
  return myObject;;
}

No errors are shown in line 1 due to ;; but on line 2 it displays 
a "Unreacheable code" message. In this simple method it is easy to find the 
duplicate semi-colon but in a more complex structure the user could "get 
blind" and not see it.

If possible, the message should be more clear and indicate the real problem: 
(duplicate semi-colon after return statement).
Comment 1 Olivier Thomann CLA 2002-03-12 17:47:25 EST
';' represents an empty statement. So this statement is unreachable after a return. So if you 
write:
  Object myObject = new Object();;
The first semi-colon closes the local declaration 
statement and the second semi-colon is simply an empty statement. You can perfectly write this. 

When you write:
return myObject();; 
The first semi-colon closes the return statement and 
the second one is an empty statement. The JLS specifies that all statements must be reachable 
(http://java.sun.com/docs/books/jls/second_edition/html/statements.doc.html#236365). 
In your example, the first empty statement is reachable, because a field declaration doesn't 
exit the method. However the second empty statement is unreachable, because the flow of the 
execution will never reach it. It is after a return statement and this statement exits the 
method.
So as the JLS specified, the compiler returns an error saying that this empty statement 
is unreachable. If you double-click on the error in the task view, you will have the second semi-
colon highlighted, which means this is the unreachable code.
Some compilers were ignoring 
this error. Now we correctly reject such a code.
Changing the error message for something like 
"duplicate semi-colon after return statement" would be wrong. This message is used for all 
unreachable code. You could write:
 return myObject;System.out.println();
In this case we 
flag in the same way the whole statement System.out.println(); has been unreachable. The 
difference is that this is not an empty statement. So we have a generic message to report 
unreachable code and as long as we highlight the whole statement (reduced to a single semi-colon in 
the case of an empty statement) I don't see anything wrong with that.
Ok to close?
Comment 2 Rodrigo Peretti CLA 2002-03-12 17:52:36 EST
Sure.
Comment 3 Philipe Mulet CLA 2002-03-13 04:52:14 EST
Empty statements are unfortunately true statements, and have to be reported by 
the compiler when unreachable.

Closing
Comment 4 Olivier Thomann CLA 2004-08-23 18:57:56 EDT
*** Bug 72467 has been marked as a duplicate of this bug. ***