Sunday, 13 August 2017

WTF code! ~ foundjava

While I was looking at some legacy code I stumbled upon a few wtf! moments. This is code that surprised me and made me laugh. Not that I haven’t written bad code in my life, but this is hilarious.
1
setPMPLogHistory(new Integer(applicationId).toString());
In the code above, the variable applicationId is already a String! The developer first creates a new Integer instance from a String and then turns this into a String again!
1
info.getApplicationTypeID().equalsIgnoreCase("1")
Apart from the obvious refactoring (the “1” should be at the beginning of the comparison in order to avoid a npe) you don’t have upper/lower case digits, so the equalsIgnoreCase is unnecessary.

No comments:

Post a Comment