The Artima Developer Community
Sponsored Link

Java Buzz Forum
The null pointer scandal

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Norman Richards

Posts: 396
Nickname: orb
Registered: Jun, 2003

Norman Richards is co-author of XDoclet in Action
The null pointer scandal Posted: Aug 8, 2007 6:03 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Norman Richards.
Original Post: The null pointer scandal
Feed Title: Orb [norman richards]
Feed URL: http://members.capmac.org/~orb/blog.cgi/tech/java?flav=rss
Feed Description: Monkey number 312,978,199
Latest Java Buzz Posts
Latest Java Buzz Posts by Norman Richards
Latest Posts From Orb [norman richards]

Advertisement

It seems that autoboxing is evil because you can get a null pointer - and your IDE doesn't even warn you of the horrific danger. That's right, check out this scandalous code:

int sucker = thisMethodReallyReturnsAnIntegerNotAnInt();

I tried it out myself, and David is right: "No squiggly red line in your Eclipse editor". And you really get NullPointerException when you return a null. Oh my!

Shocked by the horror of it, I set off in search of similar dangers. And, my dear Java friends, you aren't going to believe what I've uncovered. Check out this fiendish piece of code.

String sucker = iHopeThisMethodDoesntReturnNull().toString();

I know what you are thinking. "I've written code like that before." So have I, and I thought I was completely safe. My IDE certainly didn't give me a red squiggly line. Normally this code works like a charm, at least for the first hour or so. But if it returns null - watch out! Boom! NullPointerException!

I've seen developers spending hours and hours in their debugger trying to track things like this down. You might even have to look at a stack trace to figure it out - it's that bad! So please, please be careful friends. The world of Java is a dangerous, dangerous place!

Read: The null pointer scandal

Topic: Are You Ten Years Ago Previous Topic   Next Topic Topic: The Gnu Project has released version 4.2.1 of GCC, the GNU Compiler Collection.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use