cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gentry, Michael \(Contractor\)" <>
Subject RE: Null pointer exceptions and database null
Date Thu, 03 Aug 2006 20:31:07 GMT
I'm not 100% certain why you would want to do that (sometimes you need to know when things
are null).  I do agree it can complicate code (I really miss Objective-C's handling).  One
thing EOF did was have an EONull class to represent null objects.  You could fudge this sort
of behavior with a custom common superclass (that all the _Classes inherit from), but it wouldn't
be quite the same as if Cayenne had support for it.  This might actually be enhancement worthy,
but would probably break lots of things.


-----Original Message-----
From: [] On Behalf Of Øyvind Harboe
Sent: Thursday, August 03, 2006 4:03 PM
Subject: Null pointer exceptions and database null

Is there a way to tell Cayenne to return some other value than null
when the database contains null?

E.g. for String I want an empty string instead of null, for Integer I
want 0 instead of null, etc.

Also, I want Cayenne not to modify the database unecessarily, e.g. if
Cayenne returns "" when the database contains NULL  and I write back
"" to the database, I don't want Cayenne to write an empty string to
the database, but leave the database unchanged, yet there needs to be
a way to set such database null strings to "".

My personal favourite solution to null pointer problem is
polymorphism. Create a subclass which handles the "null", "empty",
case, etc. One annoying thing about null pointers is that they are
typeless. I would have created a NullString subclass to String in some
cases, except String is final. BigDecimal is not final, so the trick
could work there. Since I'm already on my hobbyhorse: null pointers
are a plague. Much too easy to misuse. Look at the number of bug
reports in e.g. Eclipse that are NPE's(ca. 15000 out of 150000) and
the number of != null or == null checks in Eclipse is just staggering.
It vastly complicates the code. Oh well. :-)

Øyvind Harboe

View raw message