Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2005

Tip: Looking for answers? Try searching our database.

Head pgmr at my job thinks NullPointerExceptions are no problem...

Thread view: 
TimOnGoogle - 11 Aug 2005 19:33 GMT
I'd like to hear opinions on this matter -- I just started a new
job, and I noticed lots of NullPointerExceptions happening at
various places in the code.

I talked to the head engineer on this project, and he was of the
opinion that NullPointerExceptions caused by bad data or by
other circumstances other than the norm were fine, as long as
there was a top-level try/catch for them.

I have tried to let him know that, in a bullet-proof piece of
software, unusual conditions and bad data should be CHECKED
for in the code, and good error-handling implemented for specific
cases.  But he doesn't agree.

What's your opinion on this? Is it just a philosophical difference
along the lines of tabs/spaces?  Or is he just a Bad Programmer(tm)?

- Tim
Mario Winterer - 12 Aug 2005 13:37 GMT
Hi Tim!

I do not know the code you are talking about, so a specifical discussion about your special case would be frivolous.
I can just tell you about my experience concerning exception handling in general and NullPointerExceptions in particular.

First I think we must distinguish between inter-component and intra-component communication. The former is the communication between
components which should be done using the component's public APIs. The latter is the communication between component-internal
objects which uses the public- and non-public-API of the component.

The public API of a component should do parameter checking - and a wrong/illegal parameter should produce an
IllegalArgumentException - especially if an input parameter is null but it mustn't.

The non-public API is component-internal and often used by the component-developer itself only. So often there is no need for
parameter checking. Think of a situation where the public API of a component calls an internal method which again calls internal
methods and so on, and each called method hands on its input parameter. If each method did input validation, the same variable would
be checked again and again - e.g. against null - although the public API already ensured that the parameter is not null! Thats an
unnecessary effort!
As a result, illegal parameters inside non-public API methods might produce a NullPointerException - or any other exception
according to the algorithm that uses the parameters.

But in both cases - public and non-public-API an exception is what it says: An non-standard termination of the method call! A thrown
non-checked exception (i.e. RuntimeExceptions and subclasses - like NullPointerException) almost always meanst that there is a bug
in the code - otherwise you would have expected the exception and use a checked exception instead that MUST be catched or rethrown
by the caller. Illegal user input is NO bug (ok, often it is a brain-bug of the user, but not a bug of the software) - so there
should never be thrown an non-checked exception in that case (as always: The exception proves the rule)!

Please tell me your opinion about that!

Best regards,
 Tex

(BTW: Should/Must software always be "bullet proof"? I'm currently building a house - my windows aren't bullet proof! Of course - I
wish it was, but that's a matter of optics (the thick glass) and costs!)

> I'd like to hear opinions on this matter -- I just started a new
> job, and I noticed lots of NullPointerExceptions happening at
[quoted text clipped - 14 lines]
>
> - Tim


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.