I typed this into Eclipse, and it's super-awesome-excellent auto-code-writer decided that it should be:
public int doubleFooBarBazQux(Foo foo) throws NullPointerException {
try {
return foo.bar().baz().qux() * 2;
}
catch(NullPointerException e){
throw new NullPointerException(e.getMessage());
}
}
If only there was a right-click option for "improve quality"...Yeah, the generated code is asinine, but what would you prefer? "Improve quality" in this case would just leave out the try/catch altogether. Is there another behavior that would be better, given that we know nothing about foo, bar, baz, or qux?
Say you have
That might throw a NPE, but what's the alternative?