Re: Protection against NPEs/catching illegal arguments ASAP

From: Holger Hoffstätte (holge..izards.de)
Date: Sat Dec 07 2002 - 18:47:34 EST

  • Next message: Holger Hoffstätte: "Reengineer Db makes window jump?"

    One more quick thought:

    Holger Hoffstätte wrote:
    > ..
    > I don't know any good solution to this either, especially for cases where
    > nulls are allowed and needed (like in Modeler, as you said); it's a
    > difficult choice to make. Still, most of the time NPE avoidance (by e.g.
    > gracefully doing nothing after a check) is IMHO preferrable to crashing or
    > exception throwing.

    One thing I found useful as a general rule-of-thumb for my own classes and
    collection extensions for the last couple of years is that:

    - methods which return single objects can return null to indicate 'no
    result'
    - methods which return a collection must never return null, but rather an
    empty collection

    I know these look trivial and kind of obvious, but they can really help
    reduce a large number of bugs.

    Holger



    This archive was generated by hypermail 2.0.0 : Sat Dec 07 2002 - 18:47:41 EST