Archive

Archive for the ‘WTF’ Category

WTF again

30 November 2016 1 comment

Looking at legacy code, someone actually wrote a class that extends ArrayList

public class UserInterfaceModel extends ArrayList {

just because (s)he wanted to find out if a specific element was in the list!

public class UserInterfaceModel extends ArrayList {
    private static final long serialVersionUID = 1L;

    public UserInterfaceModel() {}

    public void addElement(UserInterfaceElement uie) {
        this.add(uie);
    }

    //chek if contains UserInterfaceElement in collection
    public boolean isContainingElement(String name) {
        for (int i=0;i<this.size();i++) {
            if (((UserInterfaceElement)this.get(i)).getName().equalsIgnoreCase(name)) {
                return true;
             }
         }
         return false;
    }
}

public class UserInterfaceElement {

    private String name;
    private String url;
...
}

Instead, the said programmer could just implement the equals method in the UserInterfaceElement element (to check only the name value) and just use a List.

Amzing, just amazing.

Advertisements
Categories: Java, WTF

Yet another WTF moment

4 June 2014 5 comments
boolean found = false;
for (int pr=0; pr<promotions.length; pr++) {
    Promotion promotion = promotions[pr];
    if (promotion!=null && promotion.getName().equals(""+availablePromotions[pr][a1].getPackageId())) {
        externalPromotions[pr] = externalPromotions[pr];    // WTF!!! Assigning a value to itself.
        found = true;  // Not sure what this is
        break;
    }
}
found = false;  // As soon as the loop exits this goes back to false again. WTF!!!

The above is an actual snippet of code from a production system (the comments are mine). And yes, I am serious.

Categories: WTF

And more!

30 January 2014 Leave a comment
if(canBeMultiplied && renewalOfferMultiplier > 0)
    discount = discount * renewalOfferMultiplier;
else
    discount = discount;
Categories: WTF

Even more WTF

29 January 2014 2 comments

And I thought that I had seen everything. But I hadn’t yet seen a wrapper to a String!!

public class OneVariableGenericVO implements java.io.Serializable
{

  private String varName;

  public OneVariableGenericVO()
  {
  }


  public OneVariableGenericVO(String varName)
  {
  	setVarName(varName);
  }

  public String getVarName()
  {
  	return this.varName;
  }

  public void setVarName(String varName)
  {
  	this.varName = varName;
  }

}

SO instead of using a String someone had the brilliant idea to wrap a String into an object and use this instead. What can I say? I am speechless.

Categories: WTF

More WTF!

15 November 2013 Leave a comment
if (true)
{
    if (externalCreditDeposit == 0)
        creditDeposit = internalCreditDeposit;
    else
        creditDeposit = intWeight * internalCreditDeposit + extWeight * externalCreditDeposit;
}

Just to make sure that it will always be executed!

// Variable declaration
        String oldMsisdn = "";
        String newMsisdn = "";
        int rows = 0;
        int cols = 0;
        int tmp = 0;
        int listPtr = 0;

Just to make sure that we know there are variable declarations!

if (request.getParameter("hasBlackberyFromTor")!=null && request.getParameter("hasBlackberyFromTor").equals("1")) {
       
                 
         }else{
        
        
         blackberryExtraPlus  = "-22";
             
         } 

Unnecessary empty if statement.

Categories: Java, WTF

Not tested yet! (WTF)

5 November 2013 1 comment

This is some production code, that fails.

// Do conjunction////NOT TESTED YET???I dont know what will happen : (
startConjunction(customers, application);

Not sure if the author forgot the comment there or it indeed is not tested. But knowing that the code might not work and not fixing it is really WTF!

Categories: Java, WTF

WTF code!

7 October 2013 1 comment

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.

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!

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.

Categories: Java, WTF