JDK-4083890 : Empty statements are not marked as unreachable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.1.3,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,solaris_2.5.1,solaris_2.6
  • CPU: generic
  • Submitted: 1997-10-03
  • Updated: 2001-10-11
  • Resolved: 2001-02-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
1.4.0 merlinFixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Just a semicolon in a method body is a null statement.  It has the full status
of a statement except that it is a noop.

Hence, the following method should not compile:

void f() {
  return;;
}

The second semicolon is a different statement and is unreachable.  There
should be an error reported that the second semicolon is unreachable.

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin FIXED IN: merlin INTEGRATED IN: merlin VERIFIED IN: merlin-beta3
2004-06-14

EVALUATION This is a bug. The ; is being picked out in the parser, but there should be a special EmptyStatement node that undergoes reachability like other statements. david.stoutamire@Eng 1997-10-06 This bug exists in the jdk1.3 compiler. iris.garcia@eng 1999-10-28 Well, I fixed it (the tree is called Skip), and discovered how often people write things like return 0;/* exit success */; and { return f(); } catch (Whatever e) { throw new Whatever2(); }; Note the extra semicolon in both cases. I fixed a number of problems in JDK sources and reported a number of JCK test cases that are broken. And I'll bet we get lots of problem reports from users once this bug fix makes it public. My plan is to dup those bug reports to this one, so people see WHY it isn't a compiler bug but rather was a bug in their sources that the compiler simply wasn't catching before. neal.gafter@Eng 2001-02-05
2001-02-05

PUBLIC COMMENTS <p>The compiler now detects unreachable empty statements as required by the language specification. <p>While people don't normally write unreachable statements intentionally, they can easily arise accidentally. Here are two of the most common types of cases we've seen since the compiler started catching them: <pre> return 0;/* exit success */; </pre> and <pre> { return f(); } catch (Whatever e) { throw new Whatever2(); }; </pre> <p>Note the extra semicolon in both cases. In addition, some automatically generated source code may generate unreachable empty statements. neal.gafter@Eng 2001-02-05
2001-02-05