You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Maas van den Berg <em...@dds.nl> on 2003/08/14 00:57:00 UTC

[PATCH] jsr88 DeploymentFactoryManager implementation + unittests

TIA,
Maas

Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by Aaron Mulder <am...@alumni.princeton.edu>.
	But I think we should aim to duplicate the behavior defined by the 
spec, not the idiosyncracies present in the RI.  The doc doesn't say 
anywhere that you should be able to register a null factory, and again, 
why iterate through a list full of nulls and duplicate entries?

Aaron

On Thu, 14 Aug 2003 email@dds.nl wrote:
> Personaly I agree completely, but I discovered this behaviour while
> writing the unittest against SUNs reference implementation. 
> I had to remove the null check from my original code to make the test
> failures go away. :)


Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by em...@dds.nl.
James,

Personaly I agree completely, but I discovered this behaviour while
writing the unittest against SUNs reference implementation. 
I had to remove the null check from my original code to make the test
failures go away. :)

Maas

Citeren James Strachan <ja...@yahoo.co.uk>:

> 
> On Thursday, August 14, 2003, at 06:31  am, Aaron Mulder wrote:
> 
> > Maas,
> >
> > 	Regarding this particular patch, I'd prefer that we don't actually
> > add "null" to the list of DeploymentFactories, even if it's passed as 
> > an
> > argument to DeploymentFactoryManager.registerDeploymentFactory().  
> > That's
> > silly, we should just ignore a null.
> 
> Failing fast with silly arguments is a good idea - e.g. throw an 
> IllegalArgumentException or NullPointerException.
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> 
> 




Re: [Error handling] NullPointer or IllegalArgument?

Posted by Berin Loritsch <bl...@apache.org>.
Alex Blewitt wrote:

> On Thursday, Aug 14, 2003, at 18:17 Europe/London, Berin Loritsch wrote:
> 
>> Alex Blewitt wrote:
>>
>>> Why bother? RuntimeException has an argument to pass in the exception 
>>> type to the superclass ...
>>
>> Clarity.  For the same reason that you complained about not being able
>> to differentiate between an NPE thrown by the system and one thrown by
>> our code.  You can't differentiate a RuntimeException that holds an
>> IOException and one that holds a SQLException if all you use are
>> RuntimeExceptions.
>>
>> New exception types don't need to all be thought up in advance.  You can
>> create them as you find you have need.
> 
> 
> The question is, do you really need to be able to catch both exception 
> types distinctly? You can instead use:
> 
> } (catch RuntimeException e) {
>   Throwable cause = e.getCause();
>   if (cause instanceof IOException) {
>   } else if (cause instanceof SQLException) {
>   } ...
> }
> 
> I think this topic has had enough open airing in this mailing list now 
> anyway, and whilst (hopefully) it's provoked a few thoughts, the general 
> advice of not using RuntimeException and NullPointerException, and the 
> benefits of using IllegalArgumentException and NullArgumentException 
> have probably gone through, which was the original intent :-)
> 
> I'd be happy to take the discussion off-line and further bash out a few 
> points if you'd like to continue talking about it, though :-)


That's Ok.


-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 18:17 Europe/London, Berin Loritsch wrote:

> Alex Blewitt wrote:
>
>> Why bother? RuntimeException has an argument to pass in the exception 
>> type to the superclass ...
> Clarity.  For the same reason that you complained about not being able
> to differentiate between an NPE thrown by the system and one thrown by
> our code.  You can't differentiate a RuntimeException that holds an
> IOException and one that holds a SQLException if all you use are
> RuntimeExceptions.
>
> New exception types don't need to all be thought up in advance.  You 
> can
> create them as you find you have need.

The question is, do you really need to be able to catch both exception 
types distinctly? You can instead use:

} (catch RuntimeException e) {
   Throwable cause = e.getCause();
   if (cause instanceof IOException) {
   } else if (cause instanceof SQLException) {
   } ...
}

I think this topic has had enough open airing in this mailing list now 
anyway, and whilst (hopefully) it's provoked a few thoughts, the 
general advice of not using RuntimeException and NullPointerException, 
and the benefits of using IllegalArgumentException and 
NullArgumentException have probably gone through, which was the 
original intent :-)

I'd be happy to take the discussion off-line and further bash out a few 
points if you'd like to continue talking about it, though :-)

Alex.


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Berin Loritsch <bl...@apache.org>.
Alex Blewitt wrote:

> Why bother? RuntimeException has an argument to pass in the exception 
> type to the superclass, in the form of a nested exception (accessed by 
> Throwable.getCause()).
> 
> By your reasoning, every different subtype would have its own class:
> IORuntimeException
> TextRuntimeException
> SQLRuntimeException
>  :
> 
> I've only got one:
> 
> RuntimeException
> 
> :-)

Clarity.  For the same reason that you complained about not being able
to differentiate between an NPE thrown by the system and one thrown by
our code.  You can't differentiate a RuntimeException that holds an
IOException and one that holds a SQLException if all you use are
RuntimeExceptions.

New exception types don't need to all be thought up in advance.  You can
create them as you find you have need.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
Why bother? RuntimeException has an argument to pass in the exception 
type to the superclass, in the form of a nested exception (accessed by 
Throwable.getCause()).

By your reasoning, every different subtype would have its own class:
IORuntimeException
TextRuntimeException
SQLRuntimeException
  :

I've only got one:

RuntimeException

:-)

On Thursday, Aug 14, 2003, at 17:37 Europe/London, Berin Loritsch wrote:

> Alex Blewitt wrote:
>
>> (*) Yes, you could argue that it's a bad API, and that IOException 
>> should be added to the throws clause. But particularly, when you're 
>> dealing with an interface (e.g. java.util.Iterator) or an abstract 
>> super-type (java.util.AbstractTreeModel) you don't often have the 
>> ability to change the supertype method definition ...
>
> Just create an IORuntimeException that can be caught that explicitly
> holds the parent IOException....
>
> THat approach is a documented pattern (can't remember where I've seen
> it though).  I still prefer a typed exception to a generic one.

Absolutely, and I was never advocating RuntimeExceptions in place of 
Exceptions. I was pointing out there are some places where you /cannot/ 
use Exception, and you're stuck with RuntimeExceptions.

So, in order of decreasing preferences:

JavaSubclassOfException -> MyOwnSubclassOfException -> 
JavaSubclassOfRuntimeException -> MyOwnSubclassOfRuntimeException -> 
RuntimeException/NullPointerException

:-)


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Berin Loritsch <bl...@apache.org>.
Alex Blewitt wrote:


> 
> Alex.
> 
> (*) Yes, you could argue that it's a bad API, and that IOException 
> should be added to the throws clause. But particularly, when you're 
> dealing with an interface (e.g. java.util.Iterator) or an abstract 
> super-type (java.util.AbstractTreeModel) you don't often have the 
> ability to change the supertype method definition ...

Just create an IORuntimeException that can be caught that explicitly
holds the parent IOException....

THat approach is a documented pattern (can't remember where I've seen
it though).  I still prefer a typed exception to a generic one.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 15:26 Europe/London, Berin Loritsch wrote:

> Alex Blewitt wrote:
>
> <snip/>
>
>>> A typed exception works much better as you can make more specific 
>>> actions if
>>> necessary.  I am not saying to never extend a runtime exception, but 
>>> I am
>>> saying don't use it directly.  IMNSHO RuntimeException and Exception 
>>> should
>>> be abstract base classes and not concrete at all.
>> There may well be an argument for that.
>> In any case, I wasn't advocating 'Use RuntimeExceptions for all'. I 
>> was saying that there's never a reason to want to use NPE, and if you 
>> really need to throw an unchecked exception (for example, the 
>> interface doesn't allow it) then use a RuntimeException instead.
>> Correct me if I misunderstood your post, but it seemed that you 
>> assumed I was advocating RuntimeExceptions for everthing. I wasn't. 
>> RuntimeExceptions are pretty ugly and should be avoided where 
>> possible over another implementation or a checked exception 
>> (preferably).
>> What I was saying is that NPE is an exception a programmer should 
>> never throw, and if checked exceptions or other suitable exceptions 
>> (IAE, NAE) don't allow, then throw RuntimeException instead of NPE.
>
> Actually, I would much rather see an NPE with a message (you can 
> include
> the name of the parameter in the message) than a generic 
> RuntimeException.

It may not always be easy to test between an NPE that you've raised, 
versus one that a VM has raised. For example, if there are automated 
tests and there's an NPE, that (to me) always means program bug.

> The only time an NPE gives you insufficient information is when it is
> automatically generated--there is no message to clue you in.

This is a way of detecting between an automatically raised NPE and a 
'manually' raised NPE, but not something you can simply do with a catch.

> If you are adamately opposed to NPEs, then IAE 
> (IllegalArgumentExceptions)
> are a nice alternative.  Either IMO are far better than generic
> RuntimeExceptions.

I had a long discussion about Exceptions (good and bad) and the 
conclusion we came up with was: possibly. Actually, there is a time 
when a RuntimeException is good; when you've got a method that can't 
add extra checked exception types to, and you need to throw one in your 
code:

public class Super {
   public void methodNoEx() { (*)
   }
}

pubic class Sub extends Super {
   public void methodNoExt() /* cannot throw antying else */
   {
     //
    try {
       io.read(buffer);
    } catch (IOException e) {
       throw new RuntimeException(e);
     }
}

But if you agree not to throw NPEs and use other types, then I'll agree 
not to throw generic RuntimeExceptions. Sounds like a good compromise 
to me :-)

Alex.

(*) Yes, you could argue that it's a bad API, and that IOException 
should be added to the throws clause. But particularly, when you're 
dealing with an interface (e.g. java.util.Iterator) or an abstract 
super-type (java.util.AbstractTreeModel) you don't often have the 
ability to change the supertype method definition ...


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Berin Loritsch <bl...@apache.org>.
Alex Blewitt wrote:

<snip/>

> 
>> A typed exception works much better as you can make more specific 
>> actions if
>> necessary.  I am not saying to never extend a runtime exception, but I am
>> saying don't use it directly.  IMNSHO RuntimeException and Exception 
>> should
>> be abstract base classes and not concrete at all.
> 
> 
> There may well be an argument for that.
> 
> In any case, I wasn't advocating 'Use RuntimeExceptions for all'. I was 
> saying that there's never a reason to want to use NPE, and if you really 
> need to throw an unchecked exception (for example, the interface doesn't 
> allow it) then use a RuntimeException instead.
> 
> Correct me if I misunderstood your post, but it seemed that you assumed 
> I was advocating RuntimeExceptions for everthing. I wasn't. 
> RuntimeExceptions are pretty ugly and should be avoided where possible 
> over another implementation or a checked exception (preferably).
> 
> What I was saying is that NPE is an exception a programmer should never 
> throw, and if checked exceptions or other suitable exceptions (IAE, NAE) 
> don't allow, then throw RuntimeException instead of NPE.
> 


:)

Actually, I would much rather see an NPE with a message (you can include
the name of the parameter in the message) than a generic RuntimeException.

The only time an NPE gives you insufficient information is when it is
automatically generated--there is no message to clue you in.

An NPE communicates that something was null that should not have been, and
any supplied message (which I strongly advocate) would give you the hint as
to what exactly is wrong.

An NPE thrown at the beginning of a method is far easier to test and debug
than one thrown by the JVM.  You know that code sent a null parameter that
wasn't supposed to be sent, so all you have to do is go one step back in
the stack trace to see where the culprit really is.

If you are adamately opposed to NPEs, then IAE (IllegalArgumentExceptions)
are a nice alternative.  Either IMO are far better than generic
RuntimeExceptions.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 14:19 Europe/London, Berin Loritsch wrote:

> Alex Blewitt wrote:
>
>> On Thursday, Aug 14, 2003, at 11:36 Europe/London, Jason Dillon wrote:
>>> I do not agree with the Exceptions section listed in the wiki.  I 
>>> think that a NPE can be thrown where appropriate.  For argument 
>>> methods which must not be null a NPE is not appropriate.  I think we 
>>> should change the text to make it clear that if you must throw an 
>>> NPE, then it is okay, but that you need to have a reason todo so and 
>>> that it must have a description.
>> I put that there to wean people away from the NPE re: discussions on 
>> this topic.
>> If you can give me a clear example of when throwing an NPE is 
>> desirable, please do so. But for every example you'll give, I'll ask 
>> why it couldn't be either an IllegalArgumentException (if it is to do 
>> with arguments), or if not a generic RuntimeException (with suitable 
>> messages).
>
> (Runs away screaming) NOOOOO!!!!
>
> NEVER throw a generic RuntimeException--it tells you nothing.  I am 
> currently
> maintaining a program that uses nothing but RuntimeExceptions, and 
> debugging
> the bugger is a serious pain in the arse.

It tells you more than a NullPointerException does. Consider: 
NullPointerException is generated automatically in the case of a code 
failure as you describe. Thus, if a NullPointerException is raised you 
can be sure that it comes from a null pointer error, and thus you know 
what kind of error to look for.

As soon as you start using NullPointerException to raise your own 
errors in the code, you lose that advantage. When an NPE occurs, you 
have to ask (a) Am I throwing that? or (b) Is the JVM throwing that? 
which can slow down the time taken to find and locate the bug.

On the other hand, a RuntimeException can be used as a generic 
something-has-gone-wrong-but-I-dont-have-a-specific-class-for-it, which 
therefore allows you to tell the difference between a true NPE and a 
failure event that the programmer would like to raise.

I feel sorry for you if you're maintaining code that /solely/ uses 
RuntimeExceptions, and I would agree that's a Bad Thing. Clearly, 
whenever there is a more appropriate exception (be it IAE or whatever) 
then that should be used instead, and if there's not a more suitable 
one then consider writing a new exception type.

> An exception should give you enough information to help you narrow 
> down where
> the bug originates.  Too many times the RuntimeException is caught far 
> too late
> to do anything useful with it.

Yes, in general, a checked exception will be better than an unchecked 
(e.g. RuntimeException)

> A typed exception works much better as you can make more specific 
> actions if
> necessary.  I am not saying to never extend a runtime exception, but I 
> am
> saying don't use it directly.  IMNSHO RuntimeException and Exception 
> should
> be abstract base classes and not concrete at all.

There may well be an argument for that.

In any case, I wasn't advocating 'Use RuntimeExceptions for all'. I was 
saying that there's never a reason to want to use NPE, and if you 
really need to throw an unchecked exception (for example, the interface 
doesn't allow it) then use a RuntimeException instead.

Correct me if I misunderstood your post, but it seemed that you assumed 
I was advocating RuntimeExceptions for everthing. I wasn't. 
RuntimeExceptions are pretty ugly and should be avoided where possible 
over another implementation or a checked exception (preferably).

What I was saying is that NPE is an exception a programmer should never 
throw, and if checked exceptions or other suitable exceptions (IAE, 
NAE) don't allow, then throw RuntimeException instead of NPE.

Alex.


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Berin Loritsch <bl...@apache.org>.
Alex Blewitt wrote:

> On Thursday, Aug 14, 2003, at 11:36 Europe/London, Jason Dillon wrote:
> 
>> I do not agree with the Exceptions section listed in the wiki.  I 
>> think that a NPE can be thrown where appropriate.  For argument 
>> methods which must not be null a NPE is not appropriate.  I think we 
>> should change the text to make it clear that if you must throw an NPE, 
>> then it is okay, but that you need to have a reason todo so and that 
>> it must have a description.
> 
> 
> I put that there to wean people away from the NPE re: discussions on 
> this topic.
> 
> If you can give me a clear example of when throwing an NPE is desirable, 
> please do so. But for every example you'll give, I'll ask why it 
> couldn't be either an IllegalArgumentException (if it is to do with 
> arguments), or if not a generic RuntimeException (with suitable messages).

(Runs away screaming) NOOOOO!!!!

NEVER throw a generic RuntimeException--it tells you nothing.  I am currently
maintaining a program that uses nothing but RuntimeExceptions, and debugging
the bugger is a serious pain in the ars.

An exception should give you enough information to help you narrow down where
the bug originates.  Too many times the RuntimeException is caught far too late
to do anything useful with it.

A typed exception works much better as you can make more specific actions if
necessary.  I am not saying to never extend a runtime exception, but I am
saying don't use it directly.  IMNSHO RuntimeException and Exception should
be abstract base classes and not concrete at all.

> 
> That way, NPEs can be reserved for unwanted program bugs, and fixed and 
> stamped on with all ferociousness.

If you fail early--NPE or IAE, then you can avoid most unexpected bugs.  I
used to be on the only IAE bandwagon, but then I realised that as long as
you can properly catch and determine what the error is, then NPE and IAE
really don't matter.  Both are errors that should never appear in logs.

With an NPE, which is the *real* error in the following:

void testMethod( Foo bar )
{
     bar.doSomething();
}

If bar is a required argument (by the implementation it is), then if "bar"
is null, the real exception is that the argument is null.  The JVM will
throw the exception at bar.doSomething() which is not the real error.

Something like that can be driven home better when the bar.doSomething()
method is burried deep inside a long method.  Or worse, if the method is
refactored and the call happens in a completely different method.

The ones that desparately need guards and fail-fast semantics are the
methods that are publically accessible.  Private methods can live without
the guards because they should have been caught ahead of time.

Whether it comes as an NPE or IAE doesn't really matter.  Just as long
as we fail early.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 11:36 Europe/London, Jason Dillon wrote:

> I do not agree with the Exceptions section listed in the wiki.  I 
> think that a NPE can be thrown where appropriate.  For argument 
> methods which must not be null a NPE is not appropriate.  I think we 
> should change the text to make it clear that if you must throw an NPE, 
> then it is okay, but that you need to have a reason todo so and that 
> it must have a description.

I put that there to wean people away from the NPE re: discussions on 
this topic.

If you can give me a clear example of when throwing an NPE is 
desirable, please do so. But for every example you'll give, I'll ask 
why it couldn't be either an IllegalArgumentException (if it is to do 
with arguments), or if not a generic RuntimeException (with suitable 
messages).

That way, NPEs can be reserved for unwanted program bugs, and fixed and 
stamped on with all ferociousness.

Alex.


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
I do not agree with the Exceptions section listed in the wiki.  I think 
that a NPE can be thrown where appropriate.  For argument methods which 
must not be null a NPE is not appropriate.  I think we should change 
the text to make it clear that if you must throw an NPE, then it is 
okay, but that you need to have a reason todo so and that it must have 
a description.

--jason


On Thursday, August 14, 2003, at 05:16  PM, Jason Dillon wrote:

>> org.apache.geronimo.common.NullArgumentException extends "NPE" and
>> throw new NullArgumentException("address");
>> (the class name doesn't match with NPE though)
>
> What?  NAE extends IAE... really it does.
>
> --jason
>


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
> org.apache.geronimo.common.NullArgumentException extends "NPE" and
> throw new NullArgumentException("address");
> (the class name doesn't match with NPE though)

What?  NAE extends IAE... really it does.

--jason


Re: [Error handling] NullPointer or IllegalArgument?

Posted by wo...@ybb.ne.jp.
Jason Dillon wrote:
> org.apache.geronimo.common.NullArgumentException extends IAE and 
> handles the formatting of the message too, so you can:
> 
> throw new NullArgumentException("address");

Both NPE and IAE is a RuntimeException, then what's difference between
your idea above and below ?

org.apache.geronimo.common.NullArgumentException extends "NPE" and 
throw new NullArgumentException("address");
(the class name doesn't match with NPE though)

Alex Blewitt wrote:
>An NPE (to me) means a coding bug, usually requiring a lot of hard work 
>figuring out where it came from and why it exists

then, what if u use IAE, it's easier to figure out where it came ??
I think it's all up to how to code, catch and trace.

hm...am I delaying to decide the coding standard or just a flamer ?

I cannot say which one is better right now but somehow afraid of
quick decision.

Fumitada.



Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
Ya... I am going a little crazy right now... trying to juggle if I am 
going to stay in Bangkok, move back to Chiang Mai, go back to 
California, where I am gonna work, Geronimo spec mess I made and random 
emails that come in every few seconds.

My apologies.

--jason


On Thursday, August 14, 2003, at 08:03  PM, James Strachan wrote:

>
> On Thursday, August 14, 2003, at 01:56  pm, Jason Dillon wrote:
>
>>> I guess this could be as easily internationalised as uses of the IAE 
>>> messages, but has the advantage that they're all in one place :-)
>>
>> Why is that bad?  All that needs to be internationalized is the 
>> "Attribute is null: " bits.  I do not suggest we translate the 
>> attribute name, as that is intended to be the name of the java 
>> attribute for easy javadoc refs.
>
> I think Alex was agreeing with you. i.e. by using Geronimo's  
> NullArgumentException we can put all the i18n in one place rather than 
> embedding it inside application code.
>
> James
> -------
> http://radio.weblogs.com/0112098/
>


Re: [Error handling] NullPointer or IllegalArgument?

Posted by James Strachan <ja...@yahoo.co.uk>.
On Thursday, August 14, 2003, at 01:56  pm, Jason Dillon wrote:

>> I guess this could be as easily internationalised as uses of the IAE 
>> messages, but has the advantage that they're all in one place :-)
>
> Why is that bad?  All that needs to be internationalized is the 
> "Attribute is null: " bits.  I do not suggest we translate the 
> attribute name, as that is intended to be the name of the java 
> attribute for easy javadoc refs.

I think Alex was agreeing with you. i.e. by using Geronimo's  
NullArgumentException we can put all the i18n in one place rather than 
embedding it inside application code.

James
-------
http://radio.weblogs.com/0112098/


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
> I guess this could be as easily internationalised as uses of the IAE 
> messages, but has the advantage that they're all in one place :-)

Why is that bad?  All that needs to be internationalized is the 
"Attribute is null: " bits.  I do not suggest we translate the 
attribute name, as that is intended to be the name of the java 
attribute for easy javadoc refs.

--jason


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 13:34 Europe/London, Greg Wilkins wrote:

> Jason Dillon wrote:
>>> [Exception] IllegalArgumentException: address must not be null
>> +1
>> org.apache.geronimo.common.NullArgumentException extends IAE and 
>> handles the formatting of the message too, so you can:
>> throw new NullArgumentException("address");
>
> I will only +1 the NullArgumentException if it is part of 
> internationalizing
> our Exception.  So that NullArgumentException can print out:

There is no reason why it couldn't be internationalised, like any other 
Exception type. Indeed, there's a static factory method 
NullArgumentException("fieldName",field) to do just that.

I guess this could be as easily internationalised as uses of the IAE 
messages, but has the advantage that they're all in one place :-)

> Other than that - I often find that subclassing exceptions just
> results it too extra hassle when too often most try blocks
> end with catch(Exception e) and you may as well just have
> one Exception type:
>
>   class ShitHappenedException extends Exception

True, but then that's bad client code as opposed to throwing specific 
types :-) But NAE is a subclass of IAE, so it's not expected to be 
caught on its own, just as part of a bad argument method (or more 
likely, RuntimeException.

I really think we ought to outlaw
try {

} catch(Exception e) {
// stuff
}

in the code -- it just eats too many exceptions that are desired (or at 
least, don't want to be hidden).

> But I think subclassing exceptions is good, if it is to add 
> functionality about throwing the exception (rather than catching it).

Bear in mind that as well as adding functionality, you're also 
subclassing the type. For example, EOFException is a subclass of 
IOException and adds no extra functionality, but it's a sufficiently 
common situation to be able to treat different exception types 
accordingly. When subclassing, you also subtype the superclass too ...


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
As soon as I get the JavaMail out of the way -- and with a little help 
from translators :-)

Alex.

On Thursday, Aug 14, 2003, at 13:43 Europe/London, Jason Dillon wrote:

>> I will only +1 the NullArgumentException if it is part of 
>> internationalizing
>> our Exception.  So that NullArgumentException can print out:
>>
>>   NullArgumentException: address mosto non essere null
>
> That is fine, trivial to implement, though I have never played with 
> message bundles and such, I do know that it is simple to do.
>
>> Other than that - I often find that subclassing exceptions just
>> results it too extra hassle when too often most try blocks
>> end with catch(Exception e) and you may as well just have
>> one Exception type:
>>
>>   class ShitHappenedException extends Exception
>>
>> But I think subclassing exceptions is good, if it is to
>> add functionality about throwing the exception (rather than catching 
>> it).
>
> Agreed.  The only function of NAE is to provide message formatting for 
> null arguments and null argument array elements.
>
> It does make sense to internationalize the resulting message, just did 
> not do it.  Perhaps someone will do it for me (hint, hint... anyone)?
>
> --jason
>


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
> I will only +1 the NullArgumentException if it is part of 
> internationalizing
> our Exception.  So that NullArgumentException can print out:
>
>   NullArgumentException: address mosto non essere null

That is fine, trivial to implement, though I have never played with 
message bundles and such, I do know that it is simple to do.

> Other than that - I often find that subclassing exceptions just
> results it too extra hassle when too often most try blocks
> end with catch(Exception e) and you may as well just have
> one Exception type:
>
>   class ShitHappenedException extends Exception
>
> But I think subclassing exceptions is good, if it is to
> add functionality about throwing the exception (rather than catching 
> it).

Agreed.  The only function of NAE is to provide message formatting for 
null arguments and null argument array elements.

It does make sense to internationalize the resulting message, just did 
not do it.  Perhaps someone will do it for me (hint, hint... anyone)?

--jason


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Greg Wilkins <gr...@mortbay.com>.


Jason Dillon wrote:
>> [Exception] IllegalArgumentException: address must not be null
> 
> 
> +1
> 
> org.apache.geronimo.common.NullArgumentException extends IAE and handles 
> the formatting of the message too, so you can:
> 
> throw new NullArgumentException("address");

I will only +1 the NullArgumentException if it is part of internationalizing
our Exception.  So that NullArgumentException can print out:

   NullArgumentException: address mosto non essere null

etc.

Other than that - I often find that subclassing exceptions just
results it too extra hassle when too often most try blocks
end with catch(Exception e) and you may as well just have
one Exception type:

   class ShitHappenedException extends Exception


But I think subclassing exceptions is good, if it is to
add functionality about throwing the exception (rather than catching it).

cheers



Re: [Error handling] NullPointer or IllegalArgument?

Posted by Greg Wilkins <gr...@mortbay.com>.

Jason Dillon wrote:
>> [Exception] IllegalArgumentException: address must not be null
> 
> 
> +1
> 
> org.apache.geronimo.common.NullArgumentException extends IAE and handles 
> the formatting of the message too, so you can:
> 
> throw new NullArgumentException("address");

I will only +1 the NullArgumentException if it is part of internationalizing
our Exception.  So that NullArgumentException can print out:

   NullArgumentException: address mosto non essere null

etc.

Other than that - I often find that subclassing exceptions just
results it too extra hassle when too often most try blocks
end with catch(Exception e) and you may as well just have
one Exception type:

   class ShitHappenedException extends Exception


But I think subclassing exceptions is good, if it is to
add functionality about throwing the exception (rather than catching it).

cheers



RE: [Error handling] NullPointer or IllegalArgument?

Posted by saroj kumar <ku...@wipro.com>.
Alex,

+1 for IAE. It is much easier to understand and debug.

-Saroj


>-----Original Message-----
>From: Alex Blewitt [mailto:Alex.Blewitt@ioshq.com] 
>Sent: Thursday, August 14, 2003 1:56 PM
>To: geronimo-dev@incubator.apache.org
>Subject: [Error handling] NullPointer or IllegalArgument?
>


**************************Disclaimer************************************

Information contained in this E-MAIL being proprietary to Wipro Limited is 
'privileged' and 'confidential' and intended for use only by the individual
 or entity to which it is addressed. You are notified that any use, copying 
or dissemination of the information contained in the E-MAIL in any manner 
whatsoever is strictly prohibited.

***************************************************************************

Re: [Error handling] NullPointer or IllegalArgument?

Posted by James Strachan <ja...@yahoo.co.uk>.
On Thursday, August 14, 2003, at 09:35  am, Jason Dillon wrote:

>> [Exception] IllegalArgumentException: address must not be null
>
> +1
>
> org.apache.geronimo.common.NullArgumentException extends IAE and 
> handles the formatting of the message too, so you can:
>
> throw new NullArgumentException("address");

Hey neat - you learn something new every day :)

James
-------
http://radio.weblogs.com/0112098/


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
> [Exception] IllegalArgumentException: address must not be null

+1

org.apache.geronimo.common.NullArgumentException extends IAE and 
handles the formatting of the message too, so you can:

throw new NullArgumentException("address");

;-)

--jason


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Aditya Gore <ad...@sun.com>.
+1 for IAE. NPEs are horrible beasts!

Alex Blewitt wrote:

> 
> On Thursday, Aug 14, 2003, at 09:50 Europe/London, James Strachan wrote:
> 
>> I favour IAE myself as a guideline though wouldn't rule against NPE in 
>> some code.
> 
> 
> In what situations would you use a NPE, then? I can't think of any 
> situation where an NPE could be considered useful when in all other 
> times it reports a bug.
> 
> In the situations you outline in your next message, why couldn't you use 
> (say) IAE or even RuntimeException?
> 
> Alex.
> 



Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
Um, never... or very infrequently.  I do not think I have ever written 
a bit of code that threw a NPE... not sure why I would actually.

--jason


On Thursday, August 14, 2003, at 04:03  PM, Alex Blewitt wrote:

>
> On Thursday, Aug 14, 2003, at 09:50 Europe/London, James Strachan 
> wrote:
>
>> I favour IAE myself as a guideline though wouldn't rule against NPE 
>> in some code.
>
> In what situations would you use a NPE, then? I can't think of any 
> situation where an NPE could be considered useful when in all other 
> times it reports a bug.
>
> In the situations you outline in your next message, why couldn't you 
> use (say) IAE or even RuntimeException?
>
> Alex.
>


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
Haha!  Be that a lesson to you... I am never wrong... except for when I 
am wrong and then that is a different matter all together :-P

--jason


On Thursday, August 14, 2003, at 04:46  PM, James Strachan wrote:

>
> On Thursday, August 14, 2003, at 10:30  am, Jason Dillon wrote:
>
>>> Note on further checking - NPE is not an IAE. They're both 
>>> RuntimeExceptions but thats about it. Sorry Jason I think you're 
>>> mistaken - but it would have been nice though.
>>
>> Huh?  Was there another Jason on this thread...
>
> DOH - I misread your mail (that'll teach me for giving up caffeine) - 
> I thought you implied NPE extends IAE. Sorry Jason! You really said 
> this...
>
>> org.apache.geronimo.common.NullArgumentException extends IAE and 
>> handles the formatting of the message too, so you can:
>>
>> throw new NullArgumentException("address");
>
> So we can all just throw NullArgumentException instead - cool.
>
> To make life a little simpler if you're writing a method I've added a 
> wee helper method which checks for null & throws the exception if 
> required...
>
> public void doSomething(Foo foo, Bar bar) {
> 	NullArgumentException.checkForNull("foo", foo);
> 	NullArgumentException.checkForNull("bar", bar);
>
> 	...
> }
>
> James
> -------
> http://radio.weblogs.com/0112098/
>


Re: [Error handling] NullPointer or IllegalArgument?

Posted by James Strachan <ja...@yahoo.co.uk>.
On Thursday, August 14, 2003, at 10:30  am, Jason Dillon wrote:

>> Note on further checking - NPE is not an IAE. They're both 
>> RuntimeExceptions but thats about it. Sorry Jason I think you're 
>> mistaken - but it would have been nice though.
>
> Huh?  Was there another Jason on this thread...

DOH - I misread your mail (that'll teach me for giving up caffeine) - I 
thought you implied NPE extends IAE. Sorry Jason! You really said 
this...

> org.apache.geronimo.common.NullArgumentException extends IAE and 
> handles the formatting of the message too, so you can:
>
> throw new NullArgumentException("address");

So we can all just throw NullArgumentException instead - cool.

To make life a little simpler if you're writing a method I've added a 
wee helper method which checks for null & throws the exception if 
required...

public void doSomething(Foo foo, Bar bar) {
	NullArgumentException.checkForNull("foo", foo);
	NullArgumentException.checkForNull("bar", bar);

	...
}

James
-------
http://radio.weblogs.com/0112098/


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Jason Dillon <ja...@coredevelopers.net>.
> Note on further checking - NPE is not an IAE. They're both 
> RuntimeExceptions but thats about it. Sorry Jason I think you're 
> mistaken - but it would have been nice though.

Huh?  Was there another Jason on this thread...

--jason


Re: [Error handling] NullPointer or IllegalArgument? (Or NullArgument :-)

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 10:21 Europe/London, James Strachan wrote:

> Note on further checking - NPE is not an IAE. They're both 
> RuntimeExceptions but thats about it. Sorry Jason I think you're 
> mistaken - but it would have been nice though.

I think that there was a comment that there was a class 
NullArgumentException in geronimo that was a subclass of IAE. Is it 
possible that NullPointer and NullArgument are getting confused?

Alex.


Re: [Error handling] NullPointer or IllegalArgument?

Posted by James Strachan <ja...@yahoo.co.uk>.
On Thursday, August 14, 2003, at 10:03  am, Alex Blewitt wrote:

>
> On Thursday, Aug 14, 2003, at 09:50 Europe/London, James Strachan 
> wrote:
>
>> I favour IAE myself as a guideline though wouldn't rule against NPE 
>> in some code.
>
> In what situations would you use a NPE, then? I can't think of any 
> situation where an NPE could be considered useful when in all other 
> times it reports a bug.

I'd prefer IAE. However I'm more bothered about getting a kick ass J2EE 
server that passes the TCK. Having every possible NPE case in the code 
covered is lower down my list of priorities.

> In the situations you outline in your next message, why couldn't you 
> use (say) IAE or even RuntimeException?

I'm saying lets use IAE - just lets not be too strict, its a good 
guideline.


Note on further checking - NPE is not an IAE. They're both 
RuntimeExceptions but thats about it. Sorry Jason I think you're 
mistaken - but it would have been nice though.

James
-------
http://radio.weblogs.com/0112098/


Re: [Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 09:50 Europe/London, James Strachan wrote:

> I favour IAE myself as a guideline though wouldn't rule against NPE in 
> some code.

In what situations would you use a NPE, then? I can't think of any 
situation where an NPE could be considered useful when in all other 
times it reports a bug.

In the situations you outline in your next message, why couldn't you 
use (say) IAE or even RuntimeException?

Alex.


Re: [Error handling] NullPointer or IllegalArgument?

Posted by James Strachan <ja...@yahoo.co.uk>.
I favour IAE myself as a guideline though wouldn't rule against NPE in 
some code.


On Thursday, August 14, 2003, at 09:25  am, Alex Blewitt wrote:

> On Thursday, Aug 14, 2003, at 07:57 Europe/London, James Strachan 
> wrote:
>
>> On Thursday, August 14, 2003, at 06:31  am, Aaron Mulder wrote:
>>
>>> Maas,
>>>
>>> egarding this particular patch, I'd prefer that we don't actually
>>> add "null" to the list of DeploymentFactories, even if it's passed 
>>> as an
>>> argument to DeploymentFactoryManager.registerDeploymentFactory().  
>>> That's
>>> silly, we should just ignore a null.
>>
>> Failing fast with silly arguments is a good idea - e.g. throw an 
>> IllegalArgumentException or NullPointerException.
>
> I've never liked the idea of a method throwing an NPE when passed a 
> null argument. A bunch of the Java data structures do this, and I've 
> had pains when they do so.
>
> An NPE (to me) means a coding bug, usually requiring a lot of hard 
> work figuring out where it came from and why it exists
>
> An IllegalArgumentException means that a method has been passed a 
> wrong value (i.e. value out of range, string in wrong format, null 
> value passed when arg was required), and usually has some kind of 
> error message associated with it.
>
> Go on, tell me which you'd prefer to see in the logs:
>
> [Exception] NullPointerException
>
> [Exception] IllegalArgumentException: address must not be null
>
> Alex.
>
> PS Votes for saying 'never throw NPEs in methods; use IAE instead?' in 
> the coding standards?
>
>

James
-------
http://radio.weblogs.com/0112098/


[Error handling] NullPointer or IllegalArgument?

Posted by Alex Blewitt <Al...@ioshq.com>.
On Thursday, Aug 14, 2003, at 07:57 Europe/London, James Strachan wrote:

> On Thursday, August 14, 2003, at 06:31  am, Aaron Mulder wrote:
>
>> Maas,
>>
>> egarding this particular patch, I'd prefer that we don't actually
>> add "null" to the list of DeploymentFactories, even if it's passed as 
>> an
>> argument to DeploymentFactoryManager.registerDeploymentFactory().  
>> That's
>> silly, we should just ignore a null.
>
> Failing fast with silly arguments is a good idea - e.g. throw an 
> IllegalArgumentException or NullPointerException.

I've never liked the idea of a method throwing an NPE when passed a 
null argument. A bunch of the Java data structures do this, and I've 
had pains when they do so.

An NPE (to me) means a coding bug, usually requiring a lot of hard work 
figuring out where it came from and why it exists

An IllegalArgumentException means that a method has been passed a wrong 
value (i.e. value out of range, string in wrong format, null value 
passed when arg was required), and usually has some kind of error 
message associated with it.

Go on, tell me which you'd prefer to see in the logs:

[Exception] NullPointerException

[Exception] IllegalArgumentException: address must not be null

Alex.

PS Votes for saying 'never throw NPEs in methods; use IAE instead?' in 
the coding standards?


Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by James Strachan <ja...@yahoo.co.uk>.
On Thursday, August 14, 2003, at 06:31  am, Aaron Mulder wrote:

> Maas,
>
> 	Regarding this particular patch, I'd prefer that we don't actually
> add "null" to the list of DeploymentFactories, even if it's passed as 
> an
> argument to DeploymentFactoryManager.registerDeploymentFactory().  
> That's
> silly, we should just ignore a null.

Failing fast with silly arguments is a good idea - e.g. throw an 
IllegalArgumentException or NullPointerException.

James
-------
http://radio.weblogs.com/0112098/


Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by Aaron Mulder <am...@alumni.princeton.edu>.
Maas,

	Regarding this particular patch, I'd prefer that we don't actually
add "null" to the list of DeploymentFactories, even if it's passed as an
argument to DeploymentFactoryManager.registerDeploymentFactory().  That's
silly, we should just ignore a null.  Also, for the register method, it
would be nice to only add the argument if it's not already in the list --
it'll be fairly common for the factory to register in a static initializer
but for the tool to perform the registration manually on top of that
(since the static initializer is only recommended, not required).  
Therefore we may as well do what we can to cut down on this redundancy so
you don't have to search an extra-long list on every request.

	As for the earlier code, can you add equals() and hashCode()  
implementations to all the *Type objects, and add unit tests that compare
them to enforce this?  I'm not sure if the Sun impl does it, but it seems
more reasonable to code like:

if(argumentVersion.equals(DConfigBeanVersionType.V1_4)) {...}

	So I want to be sure that works, even if we personally decide not 
to use that style.

Aaron


Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by em...@dds.nl.
Thanks,
Maas

Citeren James Strachan <ja...@yahoo.co.uk>:

> Great work Maas - patch applied, thanks.
> 
> Only change I did was to add the apache licence to the unit test cases.
> 
> On Wednesday, August 13, 2003, at 11:57  pm, Maas van den Berg wrote:
> 
> > TIA,
> > Maas
> > <jsr88-DeploymentFactoryManagerTest.jar><patch-jsr88- 
> > DeploymentFactoryManager>
> 
> James
> -------
> http://radio.weblogs.com/0112098/
> 
> 




Re: [PATCH] jsr88 DeploymentFactoryManager implementation + unittests

Posted by James Strachan <ja...@yahoo.co.uk>.
Great work Maas - patch applied, thanks.

Only change I did was to add the apache licence to the unit test cases.

On Wednesday, August 13, 2003, at 11:57  pm, Maas van den Berg wrote:

> TIA,
> Maas
> <jsr88-DeploymentFactoryManagerTest.jar><patch-jsr88- 
> DeploymentFactoryManager>

James
-------
http://radio.weblogs.com/0112098/