« Bad drive + flaky raid = unhappy server | Main | What do you call satire that isn't.. »

Obscure code of the week

Not so much obscure as just.. well.. bad.. or more of the "what the hell" category.

(context: in a catch exception block, e being the Exception being caught)

object.setResponseError(new Integer(e.getErrorCode()).toString(),e.getMessage());

*blink* For just one line of simple code, it sure grabbed my attention.

Comments

Which bit is the weird bit?

Yeah, I don’t see the weirdness either.

Thinking back to other occasions, I suppose you’ll say there should be at least a temporary variable in there. Is that it, though?

Creating an Integer object ouf of a primitive int just to get its String value....

The weird bit is one used to denote the sign of the exponent in a floating point number.

kasia: ah. I wondered that there’s got to be (at least) some class method for the job. What would the idiomatic way of doing this be, for us non-Java folk?

Most people would use String.valueOf(int). .. Really, biggest problem with that code is how misleading it is.

let me introduce you to http://thedailywtf.com/

Cheese your way out:

object.setResponseError(""+e.getErrorCode(),e.getMessage());