Home > java > Bugs – The most common kind

Bugs – The most common kind

I was testing an application today and came across a bug. A screen had some CRUD operations on a resource. The problem was, whatever I did, the system would perform the operation and tell me that the resource already existed. This left me scratching my head for quite a while. I add a resource and it says it already exists and then adds it. Delete and update also do the same.

So the debugging process started and I sat down with eclipse to get to the root of the problem. I verified that indeed the CRUD operations were reflecting in the persistence store. Then I came across these magical lines of code

public static final String S_SOMETHING_EXISTS = "something.already.exists";
public static final String S_SOMETHING_ADD_SUCCESS = "something.already.exists";
public static final String S_SOMETHING_DELETE_FAIL = "something.already.exists";
public static final String S_SOMETHING_DELETE_SUCCESS = "something.already.exists";

This left me smacking my head. It should have been

public static final String S_SOMETHING_EXISTS = "something.already.exists";
public static final String S_SOMETHING_ADD_SUCCESS = "something.add.success";
public static final String S_SOMETHING_DELETE_FAIL = "something.delete.failed";
public static final String S_SOMETHING_DELETE_SUCCESS = "something.delete.success";

The bug was introduced when I copied the first constant and pasted it three times. I forgot to change the keys :mrgreen: . My point is, most of the bugs that I see introduced into the system are due to silly mistakes like the one above. This is where tools like FindBugs (which can be extended with your own rules) and CheckStyle and other bug finder / code review tools come in handy. A human code review is also a great tool. This little bug served as a reminder as to why we have such tools. To a developer this bug might seem small, but wait till an end user sees the message and says ‘What gives !’.





Categories: java Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.