The FindBugs Blog

Monday, November 13, 2006

WTF in javax.sql.rowset.serial.SerialRef

Sometimes, a bug report will point you to some code that just elicits a WTF response.

FindBugs generated a null pointer warning in javax.sql.rowset.serial.SerialRef, complaining about the call if (!object.equals(null)):

/**
* Returns an Object representing the SQL structured type
* to which this SerialRef object refers. The attributes
* of the structured type are mapped according to the given type map.
*
* @param map a java.util.Map object containing zero or
* more entries, with each entry consisting of 1) a String
* giving the fully qualified name of a UDT and 2) the
* Class object for the SQLData implementation
* that defines how the UDT is to be mapped
* @return an object instance resolved from the Ref reference and mapped
* according to the supplied type map
* @throws SerialException if an error is encountered in the reference
* resolution
*/
public Object getObject(java.util.Map<String,Class<?>> map)
throws SerialException
{
map = new Hashtable(map);
if (!object.equals(null)) {
return map.get(object);
} else {
throw new SerialException("The object is not set");
}
}


But when you look at that code, that seems to be the least of the problems.
Why is the map being converted into a new Hashtable, and what is this method intended to do?

Since the return type of this isn't Class, I'm guessing that it should
return something other than Class objects. I'm guessing it should create an instance of the class found in the Map. Does anyone know?

This is one of the places where using a generic type would have been very useful in documenting the specification of the method, even if it wasn't that useful to users of the method. If the method had been declared as:
public <T> T getObject(java.util.Map<String,Class<? extends T>> map)
then the relationship between the map and the return value would have been exceptionally clear. Of course, I don't know if this is the intended specification of the class.

P.S. Thanks to Sun's open sourcing of Java, I no longer have to worry about posting examples with source code from Sun's JDK.

16 Comments:

At 4:48 AM, Blogger guan said...

I'm a student form China and I have use Findbugs for some days. Recently I just want to use your Eclipse-plugin on my works, but you see because the west Pacific Ocean's earthquake I can't open findbugs.sourceforge.net. So would you mind to e-mail it as an accessory to me?
My e-mail is: wgxwg1985@gmail.com
Thanks a lot.

 
At 7:26 PM, Blogger bleeeeeeeeeeeeeee said...

The feller took the money and started away; and when he was going out at the door, he sorter jerked his thumb over his shoulder--so--at Dan'l, and says again, very deliberate, Well, he says, hydrocodone I don't see no p'ints about that frog that's any better'n any other frog.. But the ostracized woman, as though she felt the deep humiliation of her position, turned sharply away, lortab and opened her parasol to shield her eyes from the sun.. Finding myself often in his vacant seat at these times, I watched the proceedings with a good deal allegra of care; and once was so much excited that I delivered my somewhat celebrated speech on the Central School District question, a speech of which the State of Maine printed some extra copies...

 
At 7:06 AM, Blogger Unknown said...

Your blog is very unique and interesting. It makes reader to come back and visit again.

Selenium Training in Chennai

 
At 2:19 AM, Blogger ciitnoida said...

Thanks for sharing these information. It’s a very nice topic. We are providing online training classes

Best Linux training in Noida
Linux Training Institute in Noida

 
At 2:21 AM, Blogger ciitnoida said...

Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.

Best bca college in noida
Top bca colleges in noida

 
At 2:50 AM, Blogger Unknown said...

best article best bless from my side
6 weeks CCNA Summer Internship
Best 6 weeks MCSE summer internship

 
At 11:25 PM, Blogger uma said...

great and useful blog



java training in Bangalore

spring training in Bangalore

java training institute in Bangalore

spring and hibernate training in Bangalore

 
At 11:29 PM, Blogger chandana said...

Really it's a very unique and interesting. It makes reader to come back and visit again.

DOT NET training in Marathahalli

dot net training institute in Marathahalli

dot net course in Marathahalli

best dot net training institute in Marathahalli

 
At 8:25 AM, Blogger uma said...

nice blog..


iot courses in Bangalore

internet of things training course in Bangalore

internet of things course in Bangalore

 
At 4:32 AM, Anonymous Anonymous said...

nice article
very useful information.
keep sharing.
Best Java training in bengaluru

 
At 12:30 AM, Blogger Repairtech Solutions said...

I really love your site.. Pleasant colors & theme. Did you create this web site yourself? Please reply back as I’m trying to create my own personal blog and would love to learn where you got this from or exactly what the theme is named. Cheers! onsite mobile repair bangalore I really like it when people come together and share views. Great blog, stick with it! asus display replacement Great information. Lucky me I recently found your site by chance (stumbleupon). I've saved as a favorite for later! huawei display repair bangalore

 
At 12:31 AM, Blogger Repairtech Solutions said...

This website was... how do you say it? Relevant!! Finally I've found something that helped me. Cheers! vivo charging port replacement Everything is very open with a very clear clarification of the challenges. It was really informative. Your site is very helpful. Thank you for sharing! lg service center Bangalore I must thank you for the efforts you have put in penning this website. I really hope to view the same high-grade content by you later on as well. In truth, your creative writing abilities has motivated me to get my very own blog now ;) motorola display repair bangalore

 
At 4:38 AM, Blogger Cristina Parker said...

Acadecraft, an optimum content quality checker online service, has a team of Content Quality Analysts who possess ultimate subject-matter knowledge. We have experienced writers who have worked on multiple challenging projects. Our QC consultants aptly identify the risk areas and rectify them.
check content quality online
video solutions development companies

 
At 5:31 AM, Blogger jordan said...

Thank you for sharing such a nice blog.Astroswamig is the famous online astrology prediction portal.here you can talk to best astrologer of India.and you know your horoscope and kundali.

Taurus Horoscope 2021
Aries Horoscope 2021
Talk To Astrologer
Aaj ka Rashifal
Online Astrologer

 
At 5:29 AM, Blogger Axel Smith said...

Such a wonderful information blog post on this topic. Do you want to accelerate your studying stuffs and thus looking for some free alternatives to Chegg? Then definitely opt for Crazy For Study website.
Their subject wise courses are curated interestingly to interact with the learners. They also have complete solution manuals to all your textbooks which make your homework easier.
So, if you want hassle-free access to free answers, then opt for Crazy For Study website. They provide you an easy access to download all study stuffs free of cost.

 
At 2:20 AM, Blogger GCP MASTERS said...

nice article
gcp data engineer training

 

Post a Comment

<< Home