The FindBugs Blog

Monday, May 14, 2007

A closed source WTF: the longest second

OK, since I've pointed out a number of times that open source code contains a number of embarrassing bugs, I want to just emphasize that I've seen embarrassing code in every code base I've examined, including some propriatary closed source code bases.

I just want to share the following code, found in the code base of a highly respected tech company.

private static final String SECOND = "second";

public static String getTimeDelayStr(long delay) {

double roundDelay = 0;

// seconds
if (delay == 1)
return String.valueOf(new Double(Math.ceil(delay)).intValue()) + " " + SECOND;
....

Tuesday, May 01, 2007

Round and Round we go; Netbeans WTF

I found the following code in a recent snapshot of netbeans. If anyone has a clue as to what the developer was thinking, let me know. The code is in org.openide.awt.HtmlLabelUI:


private static int textWidth(String text, Graphics g, Font f, boolean html) {
if (text != null) {
if (html) {
return Math.round(
Math.round(
Math.ceil(
HtmlRenderer.renderHTML(
text, g, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, f, Color.BLACK,
HtmlRenderer.STYLE_CLIP, false
)
)
)
);
} else {
return Math.round(
Math.round(
Math.ceil(
HtmlRenderer.renderPlainString(
text, g, 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE, f, Color.BLACK,
HtmlRenderer.STYLE_CLIP, false
)
)
)
);
}
} else {
return 0;
}
}

Labels:

Sorry for the long absence, I'm back

I would up getting completely swamped with some other stuff at work and not updating the findbugs blog for some time. I hope to be posting more regularly here now.