Article 47GCM CodeSOD: Why Is This Here?

CodeSOD: Why Is This Here?

by
Remy Porter
from The Daily WTF on (#47GCM)

Oma was tracking down a bug where the application complained about the wrong parameters being passed to an API. As she traced through the Java code, she spotted a construct like this:

Long s = foo.getStatusCode();if (s != null) { //do stuff} else { //raise an error}

Now, this wasn't the block which was throwing the error Oma was looking for, but she noticed a lot of if (s != null) type lines in the code. It reeked of copy/paste coding. Knowing what was about to happen, Oma checked the implementation of getStatusCode.

protected Long getStatusCode() throws ProductCustomException{Long statusCode = null; try{ statusCode = Long.valueOf(1); //Why is this here?} catch (Exception ex) { throw new ProductCustomException(ProductMessages.GENERIC_PRODUCT_MESSAGES, ex); }return statusCode;}

//Why is this here? is part of the original code. It's also the first question which popped into my head, followed by "why am I here" and "what am I doing with my life?"

For bonus points, what's not immediately clear here is that the indenting is provided via a mix of spaces and tabs.

buildmaster-icon.png [Advertisement] Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today! TheDailyWtf?d=yIl2AUoC8zAmULLBG0E6ic
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments