Bug 21868

Summary: No return statement for code with infinite loop
Product: [Eclipse Project] JDT Reporter: John Arthorne <john.arthorne>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.1 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description John Arthorne CLA 2002-07-24 14:50:27 EDT
Build: 2.0

If I compile a class with the following method:

    protected int foo() {
    	while (5 < 10) {
    		System.out.println("Foo");
    	}
    }

It reports no compilation errors.  However, this method declares a return type, 
but there is no return statement.  I would expect either, "this method must 
return a result of type int", or "this method has no way to return".  I don't 
know if the latter condition is specified in the language, so maybe it's better 
to go with the first message.
Comment 1 Philipe Mulet CLA 2002-07-25 05:06:44 EDT
No. This code is legite due to the infinite loop.

Put it this way: there is no way you can exit the method without returning 
something, given you cannot reach the method exit (without an exception).

Comment 2 Philipe Mulet CLA 2002-07-25 06:16:15 EDT
Closing
Comment 3 Adam Kiezun CLA 2002-07-25 06:25:20 EDT
here's your reference Peter
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#37316
Comment 4 Adam Kiezun CLA 2002-07-25 06:25:41 EDT
i meant: John. sorry
Comment 5 John Arthorne CLA 2002-07-25 09:42:42 EDT
Thanks Adam.  I looked through JLS but didn't find that section.  That clears it 
up.