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.
18 Comments:
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?
Very nice! I like it. skateboards pictures
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.
nice :)
I think you would be better turning word verification on, you receive lots of spam to your blog.
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.
That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
Java Training in Chennai
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
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
This blog shows that you have a great career as a content writer
Hadoop Training in Chennai
Big Data Training in Chennai
Big Data Course in Chennai
JAVA Training in Chennai
Selenium Training in Chennai
Android Training in Chennai
Nice Post...Thanks for sharing the Information...
Best IT and Non-IT Course Training Institute in Bangalore
Thank you very much for providing important information. All your information is very valuable to me.
Village Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
As a best video production company in Bangalore, we produce quality and creative videos to our clients.
Very informative blog thank you for sharing.
To make your career development the best by learning software courses by getting trained from the best software training institute in Chennai. Just select your fav... course given below.
php course in chennai
RPA Training in Chennai
Azure Training in Chennai
DevOps Training in Chennai
Cloud-computing Training in Chennai
Blue-Prsim Training in Chennai
Ui-Path Training in Chennai
Nice blog thank you .For your Sharing It's a pleasure to read your post.It's full of information I'm looking for and I'd like to express that "The content of your post is awesome"
javascript training in chennai
mysql training in chennai
unix training in chennai
Nice blog thank you .For your Sharing It's a pleasure to read your post.It's full of information I'm looking for and I'd like to express that "The content of your post is awesome"
Dotnet Training in Chennai
Core java Training in Chennai
Web design Training in Chennai
Whatsapp Number Call us Now! 01537587949
outsourcing in Bangladesh
USA pone web iphone repair USA
USA SEX WEB careful
bd sex video B tex
bd sex video sex video
bd sex video freelancing course
digital marketing at kochi
Great analysis on the null pointer bug in `setHelpMenu`! It’s surprising this issue has persisted for so long. Kudos for filing a bug report—hopefully, it leads to a fix. Keep up the good work!
bca internship | internship for bca students | sql internship | online internship for btech students | internship for 1st year engineering students
Join our Java training in Coimbatore to learn from industry experts and gain hands-on coding experience. Start your journey towards a successful tech career today
Post a Comment
<< Home