cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <joerg.heini...@gmx.de>
Subject Re: [cforms] refactoring questions (was Re: cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel Struct.java Messages.java Repeater.java MultiValueField.java AbstractContainerWidget.java Output.java Upload.java Action.java Form.java ContainerDelegate.java AbstractWidget.java Field.java Union.java BooleanField.java Widget.java)
Date Wed, 21 Apr 2004 17:25:41 GMT
On 21.04.2004 15:34, Ugo Cei wrote:

> Marc Portier wrote:
> 
>> yeah, but this is something that never needs to be catched it really 
>> is a programming error, so I find the test for null unesessary and the 
>> possible resulting NPE as more then RTE enough to commincate the 
>> coding error.
> 
> 
> The problem with the NPE is that you'd need to look at the stacktrace to 
> find what the exception is about, as you get no meaningful message, and 
> the exception might be thrown when you try to dereference the null 
> pointer, which could be far from where getId() is called. What I propose 
> is to throw a RTE when the widget is built. Fail early, if you can.
> 
> Admittedly, this is just a convenience for the developer.

NPE is really bad - not only here - for the two mentioned reasons. But 
if you insist on your NPE you can change Ugo's proposal to

if (id == null) {
   throw new NPE("id must not be null");
}

So we have NPE, which is RuntimeE, meaningful message and early failure :)

Joerg

Mime
View raw message