January 31, 2003
From the 'really bad code' collection..

I should start one.. really.

Today's gem:

public class Stupid { 

   private int _value = 0;

   public void setValue(int value) {
      if (value == _value) {
         _value = value;
      }
   }
}

Duh..huh.. huh.. why are we always seeing the same value?

Posted January 31, 2003 11:07 AM in Java
TrackBack URL for this entry: http://www.unix-girl.com/mt/mt-tb.cgi/523
Comments
On January 31, 2003 11:15 AM Steve added:

What's wrong with being really sure the two values are really equal? This is defensive programming :-)

#
On January 31, 2003 04:13 PM Breyten added:

LOL :-)

#
On February 1, 2003 08:10 AM Charles Miller added:

Here's a neat one I discovered on Friday. The most recent entry in the CVS log for this file was "Modified getOriginalException() to return 'this' instead of null"

In diagnosing the problem, it helps to keep in mind that this occurs inside a class called WrappedException.

(One day, we'll get to work with JDK1.4, and not have to re-invent wrapped exceptions with every new project... yay.)

public Throwable getOriginalException() {
Throwable e = (originalException == null) ? this : originalException;
if (e instanceof WrappedException) {
return e.getOriginalException();
}

return e;
}

#
On February 2, 2003 07:13 PM Bill de hÓra added:

Right! I see the problem - it should be public synchronized void...

#
On February 2, 2003 07:32 PM Gerald added:

Hey, I am sure this source code is protected by patent right. It seems to me as if it is descended from the Microsoft Kernel :)

#
On October 21, 2003 09:28 AM dilip added:

Hai,darling.Please send the e-mail for me and after we can identify the each other.

#
Trackbacks