Community
Participate
Working Groups
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..
"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.
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.
Verified.