Bug 319102 - Suggesting new compiler warning: This method will always return null (false);
Summary: Suggesting new compiler warning: This method will always return null (false);
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-07 06:48 EDT by Lars Svensson CLA
Modified: 2011-01-25 11:19 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Svensson CLA 2010-07-07 06:48:24 EDT
Build Identifier: 

To avoid not returning a valid value.

Reproducible: Always

Steps to Reproduce:
When I use "Create new method" from under the lightbulb menu I get this:

private String getString(){

// TODO auto-generated message stub
return null;
}


Sometims I implement it like this:

private String getString(){
String retVal = "Hello";

if(timeofDay() == EVENING){
retVal="God Evening";
}

return null;
}


Can you spot the error?? I forget to return the value of RetVal, and keeps the "return null;" instead. 

If I hade that warning turned on it would signal now... 

And if I forget to implement the original method all together it will signal as well..
Comment 1 Markus Keller CLA 2010-07-08 11:48:49 EDT
"return null;" is also often exactly what is intended. This warning would yield so many false positives that it would be useless. If you really want to see all these places, you can perform a simple text search.

A solution for you could be to avoid generating such default return statements in the first place: On "Preferences > Java > Code Style > Templates", remove ${body_statement} from the "Method body" template.
Comment 2 Dani Megert CLA 2010-07-09 02:22:17 EDT
I think a check with not too much false positives could be to report a problem if the method has a single 'return null;' along with other statements.
Comment 3 Olivier Thomann CLA 2011-01-25 11:19:31 EST
Verified.