The FindBugs Blog

Monday, September 25, 2006

A 10 year old null pointer bug

I was doing some historical analysis of FindBugs warnings in the JDK, and found that there is one null pointer warning that FindBugs generates on the 1.0.2 version of Sun's JDK that still exists in JDK 1.6.0-b99.
The bug is that if you call setHelpMenu(null) on a java.awt.MenuBar, and there is already an existing help menu, you'll get a null pointer exception. The buggy code is:

/**
* Sets the specified menu to be this menu bar's help menu.
* If this menu bar has an existing help menu, the old help menu is
* removed from the menu bar, and replaced with the specified menu.
* @param m the menu to be set as the help menu
*/
public void setHelpMenu(Menu m) {
synchronized (getTreeLock()) {
if (helpMenu == m) {
return;
}
if (helpMenu != null) {
remove(helpMenu);
}
if (m.parent != this) {
add(m);
}
helpMenu = m;
if (m != null) {
m.isHelpMenu = true;
m.parent = this;
MenuBarPeer peer = (MenuBarPeer)this.peer;
if (peer != null) {
if (m.peer == null) {
m.addNotify();
}
peer.addHelpMenu(m);
}
}
}
}

Now, the JavaDoc doesn't say that you should call setHelpMenu(null) to remove a help menu. But there is no other way to remove a help menu, and the check for if (m != null) suggests that the developer anticipated m being null. But we know that m can't be null here, because if m were null, a null pointer exception would have occurred at if (m.parent != this)

Why hasn't this been noticed or fixed in the past 10 years? I don't know, but I've now filed a bug report.

15 Comments:

At 4:31 PM, Blogger Abe said...

With NPE being one of the most common type of exceptions thrown (probably next to CCE and AIOOBE), it almost makes sense to make a non-nullable type (or make null a type). As C# has created nullable types, what about the reverse for Java?

 
At 12:51 PM, Blogger No Hassle Loans said...

Has anybody tried this Hoodia Diet Pills. I heard of the Hoodia Weightloss pills. Here is the Pure Hoodia Diet Pills or the Phentramine diet pill

 
At 11:38 PM, Blogger No Hassle Loans said...

Hey nice blog. Although it�s not what I was looking for. I am looking for info on Payday Loans or a Cash Advance so I can buy some Phentramine diet pills.. I found your blog very interesting

 
At 2:04 PM, Blogger sink sink socks said...

On inquiry if there way no provision for females , my friend called my attention to this kostenlos anal movies remarkablepsychological fact, namely:THERE IS NO SUCH THING AS A FEMALE PUNSTER.

 
At 3:16 AM, Blogger No Hassle Loans said...

Hey very interesting site. I am looking for Spy Software since kids use my pc. If you know of any worth trying just let me know. Thanks

 
At 5:36 PM, Blogger Ziomal said...

Very nice! I like it. skateboards pictures

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

This is a very cool tool to improve the code quality.

The best parts i like are NPE, Infinite Loops & Duplications. I was amazed to see some of the issues reported by this.

Thanks william for coming up with such a nice tool.

 
At 10:34 AM, Blogger Kocka said...

nice :)

I think you would be better turning word verification on, you receive lots of spam to your blog.

 
At 2:25 PM, Blogger milf said...

black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines

afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here

night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest pricefind air beds in wisconsinbest air beds in wisconsincloud air beds

best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsaircraft support equipmentsbest support equipments for aircraftsbed air informercialsbest informercials bed airmattress sized air beds

bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestThe causes of economic recessionwhat are the causes of economic recessionadjustable bed air foam The best bed air foam

hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds

migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicantdessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas

 
At 2:44 AM, Blogger jeevanbhardwaj said...

Done well. I am impressed with the standard of the data offered. I sincerely hope that you keep up with the wonderful job conducted.
Locksmith Irving TX
Locksmith In Nashville
Locksmith Berkeley CA
Locksmith Sunnyvale CA
Sunnyvale locksmith
Locksmith Sunnyvale CA
Sunnyvale locksmith
Locksmith Mesquite
irvine locksmith
pembroke pines fl locksmith
irvine locksmith
Locksmith Mesquite
irvine locksmith
locksmith miami
pembroke pines fl locksmith
plano locksmith
fort worth locksmith
plano locksmith
hialeah locksmith
fort worth locksmith
fort worth locksmith
fort worth locksmith
plano locksmith
hialeah locksmith
hialeah locksmith

 
At 10:28 PM, Blogger luck said...

Importantly make sure the Nike Air Max are very good vibrates resistancewe.Nike Air Griffey Max 1 with Nike shoe sole for traction technology and physical mobility Nike Free technology.TheNike Air Max Shoes is a beautiful ship and very flawless.The shoes Nike Air Max 180 hovercraft significantly in the heel which is visible side of the base on most models.the design using cotton lining inspired Leahter feet. There are more and more popular, the success is to make materials and design feature styles. Nike Shoes Us is worth buying, rushed to use the time for direct purchase, brings great joy to you.

 
At 10:28 PM, Blogger luck said...

Importantly make sure the Nike Air Max are very good vibrates resistancewe.Nike Air Griffey Max 1 with Nike shoe sole for traction technology and physical mobility Nike Free technology.TheNike Air Max Shoes is a beautiful ship and very flawless.The shoes Nike Air Max 180 hovercraft significantly in the heel which is visible side of the base on most models.the design using cotton lining inspired Leahter feet. There are more and more popular, the success is to make materials and design feature styles. Nike Shoes Us is worth buying, rushed to use the time for direct purchase, brings great joy to you.

 
At 9:32 AM, Blogger sping.chen said...

Said was wonderful, really the best site! Liked by the way best described 2011 Nike soccer cleats . Prefer the Nike mercurial soccer cleats and New nike soccer shoes

 
At 9:32 AM, Blogger sping.chen said...

Said was wonderful, really the best site! Liked by the way best described 2011 Nike soccer cleats . Prefer the Nike mercurial soccer cleats and New nike soccer shoes

 
At 11:49 PM, Blogger luck said...

uggs clearance There are various designs and variations available in such Uggs Outlet types of boots and also you can be assured that you will occur throughout the shoes that you desire at an affordable price.Most of those boots are made of sheep skin and are of Australian brand but there is commonly a institution within of the united states which manufactures these shoes that are extremely fashionable ugg boots clearance and look funky on both grownup men and women.

 

Post a Comment

<< Home