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;
....

13 Comments:

At 1:52 AM, Blogger Deepak Jain said...

Hi,
I started using FindBugs and came up with this error
"Usage of GetResource may be unsafe if class is extended
Calling this.getClass().getResource(...) could give results other than expected if this class is extended by a class in another package."
I tried a lot to understand it but I could not understand. Can anyone please give more details and as to why this is a bug?

Sorry I was not able to post to this blog so i had to make a comment. If you dont mind please add me to the blog so that i can post questions.[deepujain@gmail.com]
Thanks
Deepak

 
At 7:23 AM, Blogger Deepak Jain said...

I have another question.
Please answer:
After running findBugs() i had an error that describes. I understood the solution that inner class must be made static but i did not fully understand the solution. Can anyone please explain this.

Should be a static inner class
This class is an inner class, but does not use its embedded reference to the object which created it.  This reference makes the instances of the class larger, and may keep the reference to the creator object alive longer than necessary.  If possible, the class should be made static.
Thanks
Deepak

 
At 5:52 AM, Blogger Steve Smith said...

Great and Useful Article.

Online Java Training

Online Java Training from India

Online Java Training

Online Java Training From India

Java Training Institutes in Chennai

Java Training in Chennai

 
At 8:52 AM, Blogger Nainika Joseph said...


I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

SAP training in Chennai

 
At 9:02 AM, Blogger Nainika Joseph said...


I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

SAP training in Chennai

 
At 8:11 AM, Blogger Camellia Canan said...

This article creates a new hope and inspiration with in me. Thanks for sharing article like this. The way you have stated everything above is quite awesome. Keep blogging like this. Thanks.


SAP training in Chennai

 
At 7:53 AM, Blogger Camellia Canan said...

I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

SAP training in Chennai

 
At 10:26 AM, Blogger Camellia Canan said...

Thanks for the good words! Really appreciated. Great post. I ve been commenting a lot on a few blogs recently, but I had nt thought about my approach until you brought it up.

SAP training in Chennai

 
At 4:20 AM, Blogger Geetha Arcus infotech said...

My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java .

java training in chennai

 
At 5:47 AM, Blogger Keerthi said...

Really, these quotes are the holistic approach towards mindfulness. In fact, all of your posts are. Proudly saying I’m getting fruitfulness out of it what you write and share. Thank you so much to both of you.

Online Training in Chennai

 
At 1:42 AM, Blogger Suseela Susiee said...




This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.

Digital Marketing Company in Chennai

Digital Marketing Services in Chennai

 
At 2:17 AM, Blogger Vignesh PV said...

This information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
PHP Training in Chennai

 
At 6:17 AM, Blogger Evangeline Mitul said...

This is a great post. I like this topic.This site has lots of advantage. It helps me in many ways.Thanks for posting this again.

Best Laser Clinic In Chennai

Best Implant Clinic In Chennai

 

Post a Comment

<< Home