Bug 21868 - No return statement for code with infinite loop
Summary: No return statement for code with infinite loop
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-24 14:50 EDT by John Arthorne CLA
Modified: 2002-09-10 08:51 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.