#219 [248] Unreachable code as warning instead of errors

confirmed
closed-invalid
nobody
1
2001-02-12
2000-05-27
No

[248]
From tobi@web-arts.de Sat May 27 11:55:59 2000
Received: from localhost (localhost [127.0.0.1])
by www10.software.ibm.com (8.9.3/8.9.3) with ESMTP id LAA10730
for <jikes-bugs@oss.software.ibm.com>; Sat, 27 May 2000 11:55:59 -0400
Date: Sat, 27 May 2000 11:55:59 -0400
From: tobi@web-arts.de
Message-Id: <200005271555.LAA10730@www10.software.ibm.com>
To: jikes-bugs@www10.software.ibm.com
Subject: warnings instead of errors

Full_Name:
Version: 1.06
OS: Linux, NT4
Submission from: (NULL) (62.104.212.70)

Hi!

Sometimes when I develop Java software I decide to comment out some lines of
code for testing purposes. But when these lines can throw an Exception there
usually
is a try block around them that catches this Exception or the method containing
the
lines has a throws clause in its declaration.

Then the jikes compiler says that the catch block will never be reached because
the
Exception will never be thrown or something like this.

Sometimes I insert a return statement in the middle of a method because I dont
want the rest of it to be executed (debugging reasons again).

Then the compiler complains about unreachable code.

The problem is that the compiler handles these situation as fatal errors and
stops
compiling my program.

I would appreciate it if the compiler would print a warning in such a situation
and
would continue compiling.

Take a look at gcc: This C compiler has compiler flags that tell him in which
situations it shall print warnings and if it shall stop then or not.

Thanx

Tobias Barth
[248.audit]
Sun Oct 8 01:48:57 2000 cabbey moved from incoming to suggestion

Discussion

  • Eric Blake
    Eric Blake
    2001-02-12

    • status: open --> closed-invalid
     
  • Eric Blake
    Eric Blake
    2001-02-12

    Sorry, but I'm marking this as not a bug. The JLS specifically requires an error on unreachable code (14.20), and provides for the workaround you want: simply surround your unwanted statements in an if(false) block.

    public static final boolean DEBUG = false;
    void foo() {
    ..
    if (DEBUG)
    return;
    else {
    .. // unreached debug code, no compile-time error
    }
    }