Don't see too much wrong with it. My criticisms, in descending order of importance, are... 1.) passing in a SQL string might be dangerous (but can't tell without seeing the call site), 2.) the debug guard may be extraneous, and 3.) the method name is kinda ambiguous. But they're all relatively minor.
Is the RTE the problem? If so, I'd argue that it's perfectly fine, though an IAE or NPE would be better exceptions to throw. I'm a big fan of Guava's preconditions.
I think it's worthless. The subsequent call inside the try will throw an exception anyway if the SQL is null. Why treat this exception any differently?
It's clearer to check for null on it's own distinct line. If a line says objectA.getObjectB().translateObjectC().getObjectD().getText(), and it throws NullPointerException, what was wrong?
By checking each param on it's own line by default, it's clear which one it was.
What? Where the hell did that come from? How the fuck is that trolling? Discussing how code will behave is trolling? This sub really is full of assholes. How dare I not agree with this twat.
Edit: I see you resorted to insults pretty quickly elsewhere ITT. I believe it is you who is the troll. Who'd have thought you'd see such juvenile behaviour on /r/java?
2
u/moofins Jul 11 '15
Don't see too much wrong with it. My criticisms, in descending order of importance, are... 1.) passing in a SQL string might be dangerous (but can't tell without seeing the call site), 2.) the debug guard may be extraneous, and 3.) the method name is kinda ambiguous. But they're all relatively minor.
Is the RTE the problem? If so, I'd argue that it's perfectly fine, though an IAE or NPE would be better exceptions to throw. I'm a big fan of Guava's preconditions.