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.

4 Comments:

At 4:35 AM, Blogger Harald Korneliussen said...

I don't think you need to worry, no, although I believe they have not open-sourced the libraries yet. I'm 99% sure they won't sue you :-)

By the way, this is a great blog, and it looks like a great and inspiring tool. I'm downloading it to try on my own projects.

 
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 2:48 AM, Blogger sink sink socks said...

We regard the dream as quitemad, because on awaking it is with this last-named part of the dreamwork, the dream shemale sex elaboration, that we identify ourselves.Scores of little islandvessels had my grandfather seen come over the horizon, and cast anchorin the free mangasex 80 port.And a dog might tackle him and bully-rag him, and bite him,and throw him over his shoulder two or three times, and AndrewJackson--which was the name of the pup--Andrew Jackson would never leton but what he was satisfied, and hadn't expected nothing else--andthe bets being doubled and doubled on the other side all the time,till the money was all up; and then all of a sudden he would grab thatother dog jest by the j'int of his hind leg and freeze to it--notchaw, you free hentai manga download understand, but only just grip and hang on till they throwedup the sponge, if it was a year.From this short collection a further characteristic of the dreams ofchildren is manifest-- their connection with the life of deutsch sex bilder the day.

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

 

Post a Comment

<< Home