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?
Comments
What's wrong with being really sure the two values are really equal? This is defensive programming :-)
Posted by: Steve | January 31, 2003 11:15 AM
LOL :-)
Posted by: Breyten | January 31, 2003 04:13 PM
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;
}
Posted by: Charles Miller | February 1, 2003 08:10 AM
Right! I see the problem - it should be public synchronized void...
Posted by: Bill de hÓra | February 2, 2003 07:13 PM
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 :)
Posted by: Gerald | February 2, 2003 07:32 PM
Hai,darling.Please send the e-mail for me and after we can identify the each other.
Posted by: dilip | October 21, 2003 09:28 AM