Bug 81545 - "Unreachable code" erroneously reported after if( ... ) { throw ... }
Summary: "Unreachable code" erroneously reported after if( ... ) { throw ... }
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-17 12:47 EST by Anton Tagunov CLA
Modified: 2004-12-22 04:47 EST (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 Anton Tagunov CLA 2004-12-17 12:47:57 EST
Eclipse Platform
Version: 3.1.0
Build id: 200411050810

How to reproduce: compile this class

public class A
{
	void foo( int i ) throws Exception
	{
		if( i != 1 );
		{
			throw new Exception();
		}
	
		System.out.println( "bar" );
	}
}

Observed behavior: 'System.out.println( "bar" );' causes "Unreachable code" error.

Expected behavior: the code should compile w/o any errors.
Comment 1 Michael Fraenkel CLA 2004-12-21 22:46:57 EST
The error is correct.
You have a semicolon as the then clause for the if hence the throws clause
always occurs.  This makes any statements following unreachable.

If you try your code on java compiler it too should and does report the same error.
Comment 2 Frederic Fusier CLA 2004-12-22 04:43:28 EST
Thanks Michael to have pointed this :-)
Comment 3 Philipe Mulet CLA 2004-12-22 04:47:25 EST
Thanks Michael, the compiler is indeed right.
Also note that one can enable an optional compiler warning to detect empty
control flow statements like this one (which are usually just mistakes):
Preferences>Java>Compiler>Potential programming problems>Empty statement