[lang]

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[lang]

Thiago Andrade
Hello people,

Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008 the
contributors noticed that NumberUtils.max/min methods all have the same
problem:
They all throw an IllegalArgumentException when according to the official
documentation (Oracle|Sun) says that a NullPointerException must be thrown
when an argument must not be null.

However according to Apache Commons Lang Developer Guide, these methods are
all correct. This guide says that "When throwing an exception to indicate a
bad argument, always try to throw IllegalArgumentException, even if the
argument was null. Do not throw NullPointerException.".

This mail was sent in order to discuss around and make decisions to solve
this dilemma where the Java official specification says X and the Apache
official specification says Y.

My sincere thanks for your time and consideration,

--
Thiago Andrade
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Benedikt Ritter-4
Hi Thiago,


2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:

> Hello people,
>
> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
> contributors noticed that NumberUtils.max/min methods all have the same
> problem:
> They all throw an IllegalArgumentException when according to the official
> documentation (Oracle|Sun) says that a NullPointerException must be thrown
> when an argument must not be null.
>

This is not a problem imho. It is a question of API design. I don't now an
offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
at some point decided to throw NPE when ever a null reference is passed to
a method that doesn't accept null inputs. I don't feel this is right, since
a null input is also an illegal argument. Why make a differenciation? IMHO
NPE should be reserved to the JVM, when a method is called on a null
reference, but that's just my opinion.


>
> However according to Apache Commons Lang Developer Guide, these methods are
> all correct. This guide says that "When throwing an exception to indicate a
> bad argument, always try to throw IllegalArgumentException, even if the
> argument was null. Do not throw NullPointerException.".
>

Since [lang] is currently designed this way, I'd rather deal with this
issue for 4.0. We can then revisit our initial decision to only throw IAE
an maybe align it to what the JDK now does. If you want to file an issue,
my opinion is, that it should be fix version 4.0. Changing the exceptions
that are thrown now may break clients (although I think there are very few
use cases where one should catch IAE or NPE).


>
> This mail was sent in order to discuss around and make decisions to solve
> this dilemma where the Java official specification says X and the Apache
> official specification says Y.
>

Can you please provide a lnk to the official specification you're refering
to? ;-)

Regards,
Benedikt


>
> My sincere thanks for your time and consideration,
>
> --
> Thiago Andrade
>



--
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

sebb-2-2
On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:

> Hi Thiago,
>
>
> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>
>> Hello people,
>>
>> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
>> contributors noticed that NumberUtils.max/min methods all have the same
>> problem:
>> They all throw an IllegalArgumentException when according to the official
>> documentation (Oracle|Sun) says that a NullPointerException must be thrown
>> when an argument must not be null.
>>
>
> This is not a problem imho. It is a question of API design.

+1

> I don't now an
> offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
> at some point decided to throw NPE when ever a null reference is passed to
> a method that doesn't accept null inputs. I don't feel this is right, since
> a null input is also an illegal argument. Why make a differenciation? IMHO
> NPE should be reserved to the JVM, when a method is called on a null
> reference, but that's just my opinion.
>

+1.

NPE used to mean a bug had occurred rather than the user had provided bad input.

Using NPE for a parameter that must not be null confuses things.

>
>>
>> However according to Apache Commons Lang Developer Guide, these methods are
>> all correct. This guide says that "When throwing an exception to indicate a
>> bad argument, always try to throw IllegalArgumentException, even if the
>> argument was null. Do not throw NullPointerException.".
>>
>
> Since [lang] is currently designed this way, I'd rather deal with this
> issue for 4.0. We can then revisit our initial decision to only throw IAE
> an maybe align it to what the JDK now does. If you want to file an issue,
> my opinion is, that it should be fix version 4.0. Changing the exceptions
> that are thrown now may break clients (although I think there are very few
> use cases where one should catch IAE or NPE).

If Commons ever decide to switch to NPE (I hope not) then it is
imperative that the message is 100% clear that the problem is with  a
method argument, and which argument is at fault.

Otherwise we will likely find ourselves fielding bug reports about
Commons code when it is the caller that is at fault.
Even then, I suspect some reporters will just see the NPE and assume
that the Commons code has a bug.

If an argument is invalid, throw IAE.
IMO it does not make sense to throw NPE for some invalid arguments and
not others.
What Sun/Oracle perhaps should have done was introduce an
"InvalidNullArgumentException"

The Javadoc (1.7) says:

>>>
Thrown when an application attempts to use null in a case where an
object is required. These include:

Calling the instance method of a null object.
Accessing or modifying the field of a null object.
Taking the length of null as if it were an array.
Accessing or modifying the slots of null as if it were an array.
Throwing null as if it were a Throwable value.

Applications should throw instances of this class to indicate other
illegal uses of the null object.
<<<

I suppose "illegal use of the null object" could be taken to mean
passing null to a non-nullable parameter, but I think that is
stretching it too far.

>
>>
>> This mail was sent in order to discuss around and make decisions to solve
>> this dilemma where the Java official specification says X and the Apache
>> official specification says Y.
>>
>
> Can you please provide a lnk to the official specification you're refering
> to? ;-)
>
> Regards,
> Benedikt
>
>
>>
>> My sincere thanks for your time and consideration,
>>
>> --
>> Thiago Andrade
>>
>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Paul Benedict
NPE is implicit if the method does not allow an argument to be null. This
doesn't have to be the case. This has nothing to do with the JDK vs. 3rd
party source. It's just about the contract. As long as you document which
arguments can be null, then you're good -- otherwise throw an NPE to
capture the contract violation.


Cheers,
Paul


On Tue, May 6, 2014 at 12:09 PM, sebb <[hidden email]> wrote:

> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
> > Hi Thiago,
> >
> >
> > 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >
> >> Hello people,
> >>
> >> Analizing the JIRA issue
> https://issues.apache.org/jira/browse/LANG-1008the
> >> contributors noticed that NumberUtils.max/min methods all have the same
> >> problem:
> >> They all throw an IllegalArgumentException when according to the
> official
> >> documentation (Oracle|Sun) says that a NullPointerException must be
> thrown
> >> when an argument must not be null.
> >>
> >
> > This is not a problem imho. It is a question of API design.
>
> +1
>
> > I don't now an
> > offical documentation that say when IAE or NPE _must_ be thrown.
> Sun/Oracle
> > at some point decided to throw NPE when ever a null reference is passed
> to
> > a method that doesn't accept null inputs. I don't feel this is right,
> since
> > a null input is also an illegal argument. Why make a differenciation?
> IMHO
> > NPE should be reserved to the JVM, when a method is called on a null
> > reference, but that's just my opinion.
> >
>
> +1.
>
> NPE used to mean a bug had occurred rather than the user had provided bad
> input.
>
> Using NPE for a parameter that must not be null confuses things.
>
> >
> >>
> >> However according to Apache Commons Lang Developer Guide, these methods
> are
> >> all correct. This guide says that "When throwing an exception to
> indicate a
> >> bad argument, always try to throw IllegalArgumentException, even if the
> >> argument was null. Do not throw NullPointerException.".
> >>
> >
> > Since [lang] is currently designed this way, I'd rather deal with this
> > issue for 4.0. We can then revisit our initial decision to only throw IAE
> > an maybe align it to what the JDK now does. If you want to file an issue,
> > my opinion is, that it should be fix version 4.0. Changing the exceptions
> > that are thrown now may break clients (although I think there are very
> few
> > use cases where one should catch IAE or NPE).
>
> If Commons ever decide to switch to NPE (I hope not) then it is
> imperative that the message is 100% clear that the problem is with  a
> method argument, and which argument is at fault.
>
> Otherwise we will likely find ourselves fielding bug reports about
> Commons code when it is the caller that is at fault.
> Even then, I suspect some reporters will just see the NPE and assume
> that the Commons code has a bug.
>
> If an argument is invalid, throw IAE.
> IMO it does not make sense to throw NPE for some invalid arguments and
> not others.
> What Sun/Oracle perhaps should have done was introduce an
> "InvalidNullArgumentException"
>
> The Javadoc (1.7) says:
>
> >>>
> Thrown when an application attempts to use null in a case where an
> object is required. These include:
>
> Calling the instance method of a null object.
> Accessing or modifying the field of a null object.
> Taking the length of null as if it were an array.
> Accessing or modifying the slots of null as if it were an array.
> Throwing null as if it were a Throwable value.
>
> Applications should throw instances of this class to indicate other
> illegal uses of the null object.
> <<<
>
> I suppose "illegal use of the null object" could be taken to mean
> passing null to a non-nullable parameter, but I think that is
> stretching it too far.
>
> >
> >>
> >> This mail was sent in order to discuss around and make decisions to
> solve
> >> this dilemma where the Java official specification says X and the Apache
> >> official specification says Y.
> >>
> >
> > Can you please provide a lnk to the official specification you're
> refering
> > to? ;-)
> >
> > Regards,
> > Benedikt
> >
> >
> >>
> >> My sincere thanks for your time and consideration,
> >>
> >> --
> >> Thiago Andrade
> >>
> >
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Phil Steitz
In reply to this post by sebb-2-2
On 5/6/14, 10:09 AM, sebb wrote:

> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
>> Hi Thiago,
>>
>>
>> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>>
>>> Hello people,
>>>
>>> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
>>> contributors noticed that NumberUtils.max/min methods all have the same
>>> problem:
>>> They all throw an IllegalArgumentException when according to the official
>>> documentation (Oracle|Sun) says that a NullPointerException must be thrown
>>> when an argument must not be null.
>>>
>> This is not a problem imho. It is a question of API design.
> +1
>
>> I don't now an
>> offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
>> at some point decided to throw NPE when ever a null reference is passed to
>> a method that doesn't accept null inputs. I don't feel this is right, since
>> a null input is also an illegal argument. Why make a differenciation? IMHO
>> NPE should be reserved to the JVM, when a method is called on a null
>> reference, but that's just my opinion.
>>
> +1.
>
> NPE used to mean a bug had occurred rather than the user had provided bad input.
>
> Using NPE for a parameter that must not be null confuses things.
>
>>> However according to Apache Commons Lang Developer Guide, these methods are
>>> all correct. This guide says that "When throwing an exception to indicate a
>>> bad argument, always try to throw IllegalArgumentException, even if the
>>> argument was null. Do not throw NullPointerException.".
>>>
>> Since [lang] is currently designed this way, I'd rather deal with this
>> issue for 4.0. We can then revisit our initial decision to only throw IAE
>> an maybe align it to what the JDK now does. If you want to file an issue,
>> my opinion is, that it should be fix version 4.0. Changing the exceptions
>> that are thrown now may break clients (although I think there are very few
>> use cases where one should catch IAE or NPE).
> If Commons ever decide to switch to NPE (I hope not) then it is
> imperative that the message is 100% clear that the problem is with  a
> method argument, and which argument is at fault.
>
> Otherwise we will likely find ourselves fielding bug reports about
> Commons code when it is the caller that is at fault.
> Even then, I suspect some reporters will just see the NPE and assume
> that the Commons code has a bug.
>
> If an argument is invalid, throw IAE.
> IMO it does not make sense to throw NPE for some invalid arguments and
> not others.
> What Sun/Oracle perhaps should have done was introduce an
> "InvalidNullArgumentException"
>
> The Javadoc (1.7) says:
>
> Thrown when an application attempts to use null in a case where an
> object is required. These include:
>
> Calling the instance method of a null object.
> Accessing or modifying the field of a null object.
> Taking the length of null as if it were an array.
> Accessing or modifying the slots of null as if it were an array.
> Throwing null as if it were a Throwable value.
>
> Applications should throw instances of this class to indicate other
> illegal uses of the null object.
> <<<
>
> I suppose "illegal use of the null object" could be taken to mean
> passing null to a non-nullable parameter, but I think that is
> stretching it too far.

+1 to everything above.  The "illegal use of the null object" bit is
an unfortunate choice of words as it seems to have opened the door
to the s/IAE/NPE debate.  I am OK with "throw NPE early when you
know it is going to happen further down" approach when API doc does
not specify behavior, but I prefer APIs that document their
preconditions clearly and throw IAE when actual parameters violate
those preconditions.

Phil

>
>>> This mail was sent in order to discuss around and make decisions to solve
>>> this dilemma where the Java official specification says X and the Apache
>>> official specification says Y.
>>>
>> Can you please provide a lnk to the official specification you're refering
>> to? ;-)
>>
>> Regards,
>> Benedikt
>>
>>
>>> My sincere thanks for your time and consideration,
>>>
>>> --
>>> Thiago Andrade
>>>
>>
>>
>> --
>> http://people.apache.org/~britter/
>> http://www.systemoutprintln.de/
>> http://twitter.com/BenediktRitter
>> http://github.com/britter
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Michael Osipov
In reply to this post by Benedikt Ritter-4
Am 2014-05-06 15:27, schrieb Benedikt Ritter:

> Hi Thiago,
>
>
> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>
>> Hello people,
>>
>> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
>> contributors noticed that NumberUtils.max/min methods all have the same
>> problem:
>> They all throw an IllegalArgumentException when according to the official
>> documentation (Oracle|Sun) says that a NullPointerException must be thrown
>> when an argument must not be null.
>>
>
> This is not a problem imho. It is a question of API design. I don't now an
> offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
> at some point decided to throw NPE when ever a null reference is passed to
> a method that doesn't accept null inputs. I don't feel this is right, since
> a null input is also an illegal argument. Why make a differenciation? IMHO
> NPE should be reserved to the JVM, when a method is called on a null
> reference, but that's just my opinion.

It *is* a problem because NullPointerException and
IllegalArgumentException have concrete semantics layed out in the JDK's
Javadocs. If you see how both are used in the JDK, you see that NPE and
IAE are used properly and there is no such restriction to the JDK only.
If you aread Effective Java, you'll see that you *have to* use NPE if a
null argument is passed. One might remember the NullArgumentException
back in Lang 2, it was removed because it is imperative to use NPE instead.

Moreover, the Lang 3 package includes a great class, Validate, which
does things right and now I can ask, why the hell is that not used
throughout the entire library?

>> However according to Apache Commons Lang Developer Guide, these methods are
>> all correct. This guide says that "When throwing an exception to indicate a
>> bad argument, always try to throw IllegalArgumentException, even if the
>> argument was null. Do not throw NullPointerException.".

Correct to the dev guide only -- not Java.

> Since [lang] is currently designed this way, I'd rather deal with this
> issue for 4.0. We can then revisit our initial decision to only throw IAE
> an maybe align it to what the JDK now does. If you want to file an issue,
> my opinion is, that it should be fix version 4.0. Changing the exceptions
> that are thrown now may break clients (although I think there are very few
> use cases where one should catch IAE or NPE).

4.0 has to use Validate throughout the entire package. NPE and IAE
indicate a programming error in the client not adhering to the contract
depicted by the Javadocs, so it is the client's problem to deal with
them. With proper programming, you should not have to catch those
exception at all.

>> This mail was sent in order to discuss around and make decisions to solve
>> this dilemma where the Java official specification says X and the Apache
>> official specification says Y.
>>
>
> Can you please provide a lnk to the official specification you're refering
> to? ;-)

Read Effective Java on exceptions. Thiago provided a URL in the JIRA issue.

Further good resources:

1.
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
2.
http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html: "One
case where it is common practice to throw a RuntimeException is when the
user calls a method incorrectly. For example, a method can check if one
of its arguments is incorrectly null. If an argument is null, the method
might throw a NullPointerException, which is an unchecked exception."

Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Michael Osipov
In reply to this post by Benedikt Ritter-4
Am 2014-05-06 15:27, schrieb Benedikt Ritter:

> Hi Thiago,
>
>
> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>
>> Hello people,
>>
>> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
>> contributors noticed that NumberUtils.max/min methods all have the same
>> problem:
>> They all throw an IllegalArgumentException when according to the official
>> documentation (Oracle|Sun) says that a NullPointerException must be thrown
>> when an argument must not be null.
>>
>
> This is not a problem imho. It is a question of API design. I don't now an
> offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
> at some point decided to throw NPE when ever a null reference is passed to
> a method that doesn't accept null inputs. I don't feel this is right, since
> a null input is also an illegal argument. Why make a differenciation? IMHO
> NPE should be reserved to the JVM, when a method is called on a null
> reference, but that's just my opinion.

It *is* a problem because NullPointerException and
IllegalArgumentException have concrete semantics layed out in the JDK's
Javadocs. If you see how both are used in the JDK, you see that NPE and
IAE are used properly and there is no such restriction to the JDK only.
If you aread Effective Java, you'll see that you *have to* use NPE if a
null argument is passed. One might remember the NullArgumentException
back in Lang 2, it was removed because it is imperative to use NPE instead.

Moreover, the Lang 3 package includes a great class, Validate, which
does things right and now I can ask, why the hell is that not used
throughout the entire library?

>> However according to Apache Commons Lang Developer Guide, these methods are
>> all correct. This guide says that "When throwing an exception to indicate a
>> bad argument, always try to throw IllegalArgumentException, even if the
>> argument was null. Do not throw NullPointerException.".

Correct to the dev guide only -- not Java.

> Since [lang] is currently designed this way, I'd rather deal with this
> issue for 4.0. We can then revisit our initial decision to only throw IAE
> an maybe align it to what the JDK now does. If you want to file an issue,
> my opinion is, that it should be fix version 4.0. Changing the exceptions
> that are thrown now may break clients (although I think there are very few
> use cases where one should catch IAE or NPE).

4.0 has to use Validate throughout the entire package. NPE and IAE
indicate a programming error in the client not adhering to the contract
depicted by the Javadocs, so it is the client's problem to deal with
them. With proper programming, you should not have to catch those
exception at all.

>> This mail was sent in order to discuss around and make decisions to solve
>> this dilemma where the Java official specification says X and the Apache
>> official specification says Y.
>>
>
> Can you please provide a lnk to the official specification you're refering
> to? ;-)

Read Effective Java on exceptions. Thiago provided a URL in the JIRA issue.

Further good resources:

1.
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
2.
http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html: "One
case where it is common practice to throw a RuntimeException is when the
user calls a method incorrectly. For example, a method can check if one
of its arguments is incorrectly null. If an argument is null, the method
might throw a NullPointerException, which is an unchecked exception."

Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Duncan Jones
In reply to this post by Paul Benedict
On 6 May 2014 19:19, Paul Benedict <[hidden email]> wrote:
> NPE is implicit if the method does not allow an argument to be null. This
> doesn't have to be the case. This has nothing to do with the JDK vs. 3rd
> party source. It's just about the contract. As long as you document which
> arguments can be null, then you're good -- otherwise throw an NPE to
> capture the contract violation.
>
>
> Cheers,
> Paul

I'm strongly in favour of IAE for incorrect null inputs. It makes it
completely clear that the input was validated and found to be lacking.
A NPE tends to make me think something unanticipated has happened.

I agree with Sebb: NPEs will have people blaming the library before
their own code.

Duncan


>
>
> On Tue, May 6, 2014 at 12:09 PM, sebb <[hidden email]> wrote:
>
>> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
>> > Hi Thiago,
>> >
>> >
>> > 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>> >
>> >> Hello people,
>> >>
>> >> Analizing the JIRA issue
>> https://issues.apache.org/jira/browse/LANG-1008the
>> >> contributors noticed that NumberUtils.max/min methods all have the same
>> >> problem:
>> >> They all throw an IllegalArgumentException when according to the
>> official
>> >> documentation (Oracle|Sun) says that a NullPointerException must be
>> thrown
>> >> when an argument must not be null.
>> >>
>> >
>> > This is not a problem imho. It is a question of API design.
>>
>> +1
>>
>> > I don't now an
>> > offical documentation that say when IAE or NPE _must_ be thrown.
>> Sun/Oracle
>> > at some point decided to throw NPE when ever a null reference is passed
>> to
>> > a method that doesn't accept null inputs. I don't feel this is right,
>> since
>> > a null input is also an illegal argument. Why make a differenciation?
>> IMHO
>> > NPE should be reserved to the JVM, when a method is called on a null
>> > reference, but that's just my opinion.
>> >
>>
>> +1.
>>
>> NPE used to mean a bug had occurred rather than the user had provided bad
>> input.
>>
>> Using NPE for a parameter that must not be null confuses things.
>>
>> >
>> >>
>> >> However according to Apache Commons Lang Developer Guide, these methods
>> are
>> >> all correct. This guide says that "When throwing an exception to
>> indicate a
>> >> bad argument, always try to throw IllegalArgumentException, even if the
>> >> argument was null. Do not throw NullPointerException.".
>> >>
>> >
>> > Since [lang] is currently designed this way, I'd rather deal with this
>> > issue for 4.0. We can then revisit our initial decision to only throw IAE
>> > an maybe align it to what the JDK now does. If you want to file an issue,
>> > my opinion is, that it should be fix version 4.0. Changing the exceptions
>> > that are thrown now may break clients (although I think there are very
>> few
>> > use cases where one should catch IAE or NPE).
>>
>> If Commons ever decide to switch to NPE (I hope not) then it is
>> imperative that the message is 100% clear that the problem is with  a
>> method argument, and which argument is at fault.
>>
>> Otherwise we will likely find ourselves fielding bug reports about
>> Commons code when it is the caller that is at fault.
>> Even then, I suspect some reporters will just see the NPE and assume
>> that the Commons code has a bug.
>>
>> If an argument is invalid, throw IAE.
>> IMO it does not make sense to throw NPE for some invalid arguments and
>> not others.
>> What Sun/Oracle perhaps should have done was introduce an
>> "InvalidNullArgumentException"
>>
>> The Javadoc (1.7) says:
>>
>> >>>
>> Thrown when an application attempts to use null in a case where an
>> object is required. These include:
>>
>> Calling the instance method of a null object.
>> Accessing or modifying the field of a null object.
>> Taking the length of null as if it were an array.
>> Accessing or modifying the slots of null as if it were an array.
>> Throwing null as if it were a Throwable value.
>>
>> Applications should throw instances of this class to indicate other
>> illegal uses of the null object.
>> <<<
>>
>> I suppose "illegal use of the null object" could be taken to mean
>> passing null to a non-nullable parameter, but I think that is
>> stretching it too far.
>>
>> >
>> >>
>> >> This mail was sent in order to discuss around and make decisions to
>> solve
>> >> this dilemma where the Java official specification says X and the Apache
>> >> official specification says Y.
>> >>
>> >
>> > Can you please provide a lnk to the official specification you're
>> refering
>> > to? ;-)
>> >
>> > Regards,
>> > Benedikt
>> >
>> >
>> >>
>> >> My sincere thanks for your time and consideration,
>> >>
>> >> --
>> >> Thiago Andrade
>> >>
>> >
>> >
>> >
>> > --
>> > http://people.apache.org/~britter/
>> > http://www.systemoutprintln.de/
>> > http://twitter.com/BenediktRitter
>> > http://github.com/britter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Duncan Jones
In reply to this post by Phil Steitz
On 6 May 2014 20:41, Phil Steitz <[hidden email]> wrote:

> On 5/6/14, 10:09 AM, sebb wrote:
>> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
>>> Hi Thiago,
>>>
>>>
>>> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>>>
>>>> Hello people,
>>>>
>>>> Analizing the JIRA issue https://issues.apache.org/jira/browse/LANG-1008the
>>>> contributors noticed that NumberUtils.max/min methods all have the same
>>>> problem:
>>>> They all throw an IllegalArgumentException when according to the official
>>>> documentation (Oracle|Sun) says that a NullPointerException must be thrown
>>>> when an argument must not be null.
>>>>
>>> This is not a problem imho. It is a question of API design.
>> +1
>>
>>> I don't now an
>>> offical documentation that say when IAE or NPE _must_ be thrown. Sun/Oracle
>>> at some point decided to throw NPE when ever a null reference is passed to
>>> a method that doesn't accept null inputs. I don't feel this is right, since
>>> a null input is also an illegal argument. Why make a differenciation? IMHO
>>> NPE should be reserved to the JVM, when a method is called on a null
>>> reference, but that's just my opinion.
>>>
>> +1.
>>
>> NPE used to mean a bug had occurred rather than the user had provided bad input.
>>
>> Using NPE for a parameter that must not be null confuses things.
>>
>>>> However according to Apache Commons Lang Developer Guide, these methods are
>>>> all correct. This guide says that "When throwing an exception to indicate a
>>>> bad argument, always try to throw IllegalArgumentException, even if the
>>>> argument was null. Do not throw NullPointerException.".
>>>>
>>> Since [lang] is currently designed this way, I'd rather deal with this
>>> issue for 4.0. We can then revisit our initial decision to only throw IAE
>>> an maybe align it to what the JDK now does. If you want to file an issue,
>>> my opinion is, that it should be fix version 4.0. Changing the exceptions
>>> that are thrown now may break clients (although I think there are very few
>>> use cases where one should catch IAE or NPE).
>> If Commons ever decide to switch to NPE (I hope not) then it is
>> imperative that the message is 100% clear that the problem is with  a
>> method argument, and which argument is at fault.
>>
>> Otherwise we will likely find ourselves fielding bug reports about
>> Commons code when it is the caller that is at fault.
>> Even then, I suspect some reporters will just see the NPE and assume
>> that the Commons code has a bug.
>>
>> If an argument is invalid, throw IAE.
>> IMO it does not make sense to throw NPE for some invalid arguments and
>> not others.
>> What Sun/Oracle perhaps should have done was introduce an
>> "InvalidNullArgumentException"
>>
>> The Javadoc (1.7) says:
>>
>> Thrown when an application attempts to use null in a case where an
>> object is required. These include:
>>
>> Calling the instance method of a null object.
>> Accessing or modifying the field of a null object.
>> Taking the length of null as if it were an array.
>> Accessing or modifying the slots of null as if it were an array.
>> Throwing null as if it were a Throwable value.
>>
>> Applications should throw instances of this class to indicate other
>> illegal uses of the null object.
>> <<<
>>
>> I suppose "illegal use of the null object" could be taken to mean
>> passing null to a non-nullable parameter, but I think that is
>> stretching it too far.
>
> +1 to everything above.  The "illegal use of the null object" bit is
> an unfortunate choice of words as it seems to have opened the door
> to the s/IAE/NPE debate.  I am OK with "throw NPE early when you
> know it is going to happen further down" approach when API doc does
> not specify behavior, but I prefer APIs that document their
> preconditions clearly and throw IAE when actual parameters violate
> those preconditions.
>
> Phil

If consensus continues to be in the direction of IAE, do we consider
changing the behaviour of Validate.notNull() in 4.0? This currently
throws a NPE.

Duncan


>>
>>>> This mail was sent in order to discuss around and make decisions to solve
>>>> this dilemma where the Java official specification says X and the Apache
>>>> official specification says Y.
>>>>
>>> Can you please provide a lnk to the official specification you're refering
>>> to? ;-)
>>>
>>> Regards,
>>> Benedikt
>>>
>>>
>>>> My sincere thanks for your time and consideration,
>>>>
>>>> --
>>>> Thiago Andrade
>>>>
>>>
>>>
>>> --
>>> http://people.apache.org/~britter/
>>> http://www.systemoutprintln.de/
>>> http://twitter.com/BenediktRitter
>>> http://github.com/britter
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Paul Benedict
In reply to this post by Duncan Jones
It's an old debate but the "official" Java coding style has become NPE for
null arguments and IAE for invalid non-null arguments. Lang3 was supposed
to go down that path because that's how the stewards of Java (Oracle/Sun)
are coding and it's part of the best practices found in Joshua Bloch's book.


Cheers,
Paul


On Tue, May 6, 2014 at 3:50 PM, Duncan Jones <[hidden email]> wrote:

> On 6 May 2014 19:19, Paul Benedict <[hidden email]> wrote:
> > NPE is implicit if the method does not allow an argument to be null. This
> > doesn't have to be the case. This has nothing to do with the JDK vs. 3rd
> > party source. It's just about the contract. As long as you document which
> > arguments can be null, then you're good -- otherwise throw an NPE to
> > capture the contract violation.
> >
> >
> > Cheers,
> > Paul
>
> I'm strongly in favour of IAE for incorrect null inputs. It makes it
> completely clear that the input was validated and found to be lacking.
> A NPE tends to make me think something unanticipated has happened.
>
> I agree with Sebb: NPEs will have people blaming the library before
> their own code.
>
> Duncan
>
>
> >
> >
> > On Tue, May 6, 2014 at 12:09 PM, sebb <[hidden email]> wrote:
> >
> >> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
> >> > Hi Thiago,
> >> >
> >> >
> >> > 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >> >
> >> >> Hello people,
> >> >>
> >> >> Analizing the JIRA issue
> >> https://issues.apache.org/jira/browse/LANG-1008the
> >> >> contributors noticed that NumberUtils.max/min methods all have the
> same
> >> >> problem:
> >> >> They all throw an IllegalArgumentException when according to the
> >> official
> >> >> documentation (Oracle|Sun) says that a NullPointerException must be
> >> thrown
> >> >> when an argument must not be null.
> >> >>
> >> >
> >> > This is not a problem imho. It is a question of API design.
> >>
> >> +1
> >>
> >> > I don't now an
> >> > offical documentation that say when IAE or NPE _must_ be thrown.
> >> Sun/Oracle
> >> > at some point decided to throw NPE when ever a null reference is
> passed
> >> to
> >> > a method that doesn't accept null inputs. I don't feel this is right,
> >> since
> >> > a null input is also an illegal argument. Why make a differenciation?
> >> IMHO
> >> > NPE should be reserved to the JVM, when a method is called on a null
> >> > reference, but that's just my opinion.
> >> >
> >>
> >> +1.
> >>
> >> NPE used to mean a bug had occurred rather than the user had provided
> bad
> >> input.
> >>
> >> Using NPE for a parameter that must not be null confuses things.
> >>
> >> >
> >> >>
> >> >> However according to Apache Commons Lang Developer Guide, these
> methods
> >> are
> >> >> all correct. This guide says that "When throwing an exception to
> >> indicate a
> >> >> bad argument, always try to throw IllegalArgumentException, even if
> the
> >> >> argument was null. Do not throw NullPointerException.".
> >> >>
> >> >
> >> > Since [lang] is currently designed this way, I'd rather deal with this
> >> > issue for 4.0. We can then revisit our initial decision to only throw
> IAE
> >> > an maybe align it to what the JDK now does. If you want to file an
> issue,
> >> > my opinion is, that it should be fix version 4.0. Changing the
> exceptions
> >> > that are thrown now may break clients (although I think there are very
> >> few
> >> > use cases where one should catch IAE or NPE).
> >>
> >> If Commons ever decide to switch to NPE (I hope not) then it is
> >> imperative that the message is 100% clear that the problem is with  a
> >> method argument, and which argument is at fault.
> >>
> >> Otherwise we will likely find ourselves fielding bug reports about
> >> Commons code when it is the caller that is at fault.
> >> Even then, I suspect some reporters will just see the NPE and assume
> >> that the Commons code has a bug.
> >>
> >> If an argument is invalid, throw IAE.
> >> IMO it does not make sense to throw NPE for some invalid arguments and
> >> not others.
> >> What Sun/Oracle perhaps should have done was introduce an
> >> "InvalidNullArgumentException"
> >>
> >> The Javadoc (1.7) says:
> >>
> >> >>>
> >> Thrown when an application attempts to use null in a case where an
> >> object is required. These include:
> >>
> >> Calling the instance method of a null object.
> >> Accessing or modifying the field of a null object.
> >> Taking the length of null as if it were an array.
> >> Accessing or modifying the slots of null as if it were an array.
> >> Throwing null as if it were a Throwable value.
> >>
> >> Applications should throw instances of this class to indicate other
> >> illegal uses of the null object.
> >> <<<
> >>
> >> I suppose "illegal use of the null object" could be taken to mean
> >> passing null to a non-nullable parameter, but I think that is
> >> stretching it too far.
> >>
> >> >
> >> >>
> >> >> This mail was sent in order to discuss around and make decisions to
> >> solve
> >> >> this dilemma where the Java official specification says X and the
> Apache
> >> >> official specification says Y.
> >> >>
> >> >
> >> > Can you please provide a lnk to the official specification you're
> >> refering
> >> > to? ;-)
> >> >
> >> > Regards,
> >> > Benedikt
> >> >
> >> >
> >> >>
> >> >> My sincere thanks for your time and consideration,
> >> >>
> >> >> --
> >> >> Thiago Andrade
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > http://people.apache.org/~britter/
> >> > http://www.systemoutprintln.de/
> >> > http://twitter.com/BenediktRitter
> >> > http://github.com/britter
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: [lang]

Paul Benedict
In reply to this post by Duncan Jones
Yes, it's supposed to throw NPE for the reasons stated a couple times in
this thread. That's by design, not accident. The "official" version in
java.lang.Objects (JDK 7+) does the same thing.


Cheers,
Paul


On Tue, May 6, 2014 at 4:00 PM, Duncan Jones <[hidden email]> wrote:

> On 6 May 2014 20:41, Phil Steitz <[hidden email]> wrote:
> > On 5/6/14, 10:09 AM, sebb wrote:
> >> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
> >>> Hi Thiago,
> >>>
> >>>
> >>> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >>>
> >>>> Hello people,
> >>>>
> >>>> Analizing the JIRA issue
> https://issues.apache.org/jira/browse/LANG-1008the
> >>>> contributors noticed that NumberUtils.max/min methods all have the
> same
> >>>> problem:
> >>>> They all throw an IllegalArgumentException when according to the
> official
> >>>> documentation (Oracle|Sun) says that a NullPointerException must be
> thrown
> >>>> when an argument must not be null.
> >>>>
> >>> This is not a problem imho. It is a question of API design.
> >> +1
> >>
> >>> I don't now an
> >>> offical documentation that say when IAE or NPE _must_ be thrown.
> Sun/Oracle
> >>> at some point decided to throw NPE when ever a null reference is
> passed to
> >>> a method that doesn't accept null inputs. I don't feel this is right,
> since
> >>> a null input is also an illegal argument. Why make a differenciation?
> IMHO
> >>> NPE should be reserved to the JVM, when a method is called on a null
> >>> reference, but that's just my opinion.
> >>>
> >> +1.
> >>
> >> NPE used to mean a bug had occurred rather than the user had provided
> bad input.
> >>
> >> Using NPE for a parameter that must not be null confuses things.
> >>
> >>>> However according to Apache Commons Lang Developer Guide, these
> methods are
> >>>> all correct. This guide says that "When throwing an exception to
> indicate a
> >>>> bad argument, always try to throw IllegalArgumentException, even if
> the
> >>>> argument was null. Do not throw NullPointerException.".
> >>>>
> >>> Since [lang] is currently designed this way, I'd rather deal with this
> >>> issue for 4.0. We can then revisit our initial decision to only throw
> IAE
> >>> an maybe align it to what the JDK now does. If you want to file an
> issue,
> >>> my opinion is, that it should be fix version 4.0. Changing the
> exceptions
> >>> that are thrown now may break clients (although I think there are very
> few
> >>> use cases where one should catch IAE or NPE).
> >> If Commons ever decide to switch to NPE (I hope not) then it is
> >> imperative that the message is 100% clear that the problem is with  a
> >> method argument, and which argument is at fault.
> >>
> >> Otherwise we will likely find ourselves fielding bug reports about
> >> Commons code when it is the caller that is at fault.
> >> Even then, I suspect some reporters will just see the NPE and assume
> >> that the Commons code has a bug.
> >>
> >> If an argument is invalid, throw IAE.
> >> IMO it does not make sense to throw NPE for some invalid arguments and
> >> not others.
> >> What Sun/Oracle perhaps should have done was introduce an
> >> "InvalidNullArgumentException"
> >>
> >> The Javadoc (1.7) says:
> >>
> >> Thrown when an application attempts to use null in a case where an
> >> object is required. These include:
> >>
> >> Calling the instance method of a null object.
> >> Accessing or modifying the field of a null object.
> >> Taking the length of null as if it were an array.
> >> Accessing or modifying the slots of null as if it were an array.
> >> Throwing null as if it were a Throwable value.
> >>
> >> Applications should throw instances of this class to indicate other
> >> illegal uses of the null object.
> >> <<<
> >>
> >> I suppose "illegal use of the null object" could be taken to mean
> >> passing null to a non-nullable parameter, but I think that is
> >> stretching it too far.
> >
> > +1 to everything above.  The "illegal use of the null object" bit is
> > an unfortunate choice of words as it seems to have opened the door
> > to the s/IAE/NPE debate.  I am OK with "throw NPE early when you
> > know it is going to happen further down" approach when API doc does
> > not specify behavior, but I prefer APIs that document their
> > preconditions clearly and throw IAE when actual parameters violate
> > those preconditions.
> >
> > Phil
>
> If consensus continues to be in the direction of IAE, do we consider
> changing the behaviour of Validate.notNull() in 4.0? This currently
> throws a NPE.
>
> Duncan
>
>
> >>
> >>>> This mail was sent in order to discuss around and make decisions to
> solve
> >>>> this dilemma where the Java official specification says X and the
> Apache
> >>>> official specification says Y.
> >>>>
> >>> Can you please provide a lnk to the official specification you're
> refering
> >>> to? ;-)
> >>>
> >>> Regards,
> >>> Benedikt
> >>>
> >>>
> >>>> My sincere thanks for your time and consideration,
> >>>>
> >>>> --
> >>>> Thiago Andrade
> >>>>
> >>>
> >>>
> >>> --
> >>> http://people.apache.org/~britter/
> >>> http://www.systemoutprintln.de/
> >>> http://twitter.com/BenediktRitter
> >>> http://github.com/britter
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Duncan Jones
In reply to this post by Michael Osipov
On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:

>
> Am 2014-05-06 15:27, schrieb Benedikt Ritter:
>
>> Hi Thiago,
>>
>>
>> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>>
>>> Hello people,
>>>
>>> Analizing the JIRA issue
https://issues.apache.org/jira/browse/LANG-1008the
>>> contributors noticed that NumberUtils.max/min methods all have the same
>>> problem:
>>> They all throw an IllegalArgumentException when according to the
official
>>> documentation (Oracle|Sun) says that a NullPointerException must be
thrown
>>> when an argument must not be null.
>>>
>>
>> This is not a problem imho. It is a question of API design. I don't now
an
>> offical documentation that say when IAE or NPE _must_ be thrown.
Sun/Oracle
>> at some point decided to throw NPE when ever a null reference is passed
to
>> a method that doesn't accept null inputs. I don't feel this is right,
since
>> a null input is also an illegal argument. Why make a differenciation?
IMHO
>> NPE should be reserved to the JVM, when a method is called on a null
>> reference, but that's just my opinion.
>
>
> It *is* a problem because NullPointerException and
IllegalArgumentException have concrete semantics layed out in the JDK's
Javadocs. If you see how both are used in the JDK, you see that NPE and IAE
are used properly and there is no such restriction to the JDK only. If you
aread Effective Java, you'll see that you *have to* use NPE if a null
argument is passed. One might remember the NullArgumentException back in
Lang 2, it was removed because it is imperative to use NPE instead.

Effective Java is a great book, but don't confuse Joshua's advice with law.

>
> Moreover, the Lang 3 package includes a great class, Validate, which does
things right and now I can ask, why the hell is that not used throughout
the entire library?

+1 to this. We should update all of lang to use Validate once we've nailed
this issue.

Duncan

>
>
>>> However according to Apache Commons Lang Developer Guide, these methods
are
>>> all correct. This guide says that "When throwing an exception to
indicate a

>>> bad argument, always try to throw IllegalArgumentException, even if the
>>> argument was null. Do not throw NullPointerException.".
>
>
> Correct to the dev guide only -- not Java.
>
>
>> Since [lang] is currently designed this way, I'd rather deal with this
>> issue for 4.0. We can then revisit our initial decision to only throw IAE
>> an maybe align it to what the JDK now does. If you want to file an issue,
>> my opinion is, that it should be fix version 4.0. Changing the exceptions
>> that are thrown now may break clients (although I think there are very
few
>> use cases where one should catch IAE or NPE).
>
>
> 4.0 has to use Validate throughout the entire package. NPE and IAE
indicate a programming error in the client not adhering to the contract
depicted by the Javadocs, so it is the client's problem to deal with them.
With proper programming, you should not have to catch those exception at
all.
>
>
>>> This mail was sent in order to discuss around and make decisions to
solve
>>> this dilemma where the Java official specification says X and the Apache
>>> official specification says Y.
>>>
>>
>> Can you please provide a lnk to the official specification you're
refering
>> to? ;-)
>
>
> Read Effective Java on exceptions. Thiago provided a URL in the JIRA
issue.
>
> Further good resources:
>
> 1.
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> 2.
http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
"One case where it is common practice to throw a RuntimeException is when
the user calls a method incorrectly. For example, a method can check if one
of its arguments is incorrectly null. If an argument is null, the method
might throw a NullPointerException, which is an unchecked exception."
>
> Michael
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Paul Benedict
This is not a matter of law. If Oracle/Sun set a direction on how to use
NPE, it's a really good idea to follow them -- even if you don't agree, do
it for the sake of consistency. I don't think using IAE is somehow "better"
Java than what they are doing. And I give weight to what Joshua said
because he's a former architect of that company. Lang3 was designed to
throw NPE on invalid null arguments because that's what the gurus, like he,
in our industry who publish "best practices" say it should. If your opinion
bears greater weight than those set forth the best practices, then you win,
but I don't advocate going back to IAE for nulls for the reasons stated.




Cheers,
Paul


On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]> wrote:

> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
> >
> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
> >
> >> Hi Thiago,
> >>
> >>
> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >>
> >>> Hello people,
> >>>
> >>> Analizing the JIRA issue
> https://issues.apache.org/jira/browse/LANG-1008the
> >>> contributors noticed that NumberUtils.max/min methods all have the same
> >>> problem:
> >>> They all throw an IllegalArgumentException when according to the
> official
> >>> documentation (Oracle|Sun) says that a NullPointerException must be
> thrown
> >>> when an argument must not be null.
> >>>
> >>
> >> This is not a problem imho. It is a question of API design. I don't now
> an
> >> offical documentation that say when IAE or NPE _must_ be thrown.
> Sun/Oracle
> >> at some point decided to throw NPE when ever a null reference is passed
> to
> >> a method that doesn't accept null inputs. I don't feel this is right,
> since
> >> a null input is also an illegal argument. Why make a differenciation?
> IMHO
> >> NPE should be reserved to the JVM, when a method is called on a null
> >> reference, but that's just my opinion.
> >
> >
> > It *is* a problem because NullPointerException and
> IllegalArgumentException have concrete semantics layed out in the JDK's
> Javadocs. If you see how both are used in the JDK, you see that NPE and IAE
> are used properly and there is no such restriction to the JDK only. If you
> aread Effective Java, you'll see that you *have to* use NPE if a null
> argument is passed. One might remember the NullArgumentException back in
> Lang 2, it was removed because it is imperative to use NPE instead.
>
> Effective Java is a great book, but don't confuse Joshua's advice with law.
>
> >
> > Moreover, the Lang 3 package includes a great class, Validate, which does
> things right and now I can ask, why the hell is that not used throughout
> the entire library?
>
> +1 to this. We should update all of lang to use Validate once we've nailed
> this issue.
>
> Duncan
>
> >
> >
> >>> However according to Apache Commons Lang Developer Guide, these methods
> are
> >>> all correct. This guide says that "When throwing an exception to
> indicate a
> >>> bad argument, always try to throw IllegalArgumentException, even if the
> >>> argument was null. Do not throw NullPointerException.".
> >
> >
> > Correct to the dev guide only -- not Java.
> >
> >
> >> Since [lang] is currently designed this way, I'd rather deal with this
> >> issue for 4.0. We can then revisit our initial decision to only throw
> IAE
> >> an maybe align it to what the JDK now does. If you want to file an
> issue,
> >> my opinion is, that it should be fix version 4.0. Changing the
> exceptions
> >> that are thrown now may break clients (although I think there are very
> few
> >> use cases where one should catch IAE or NPE).
> >
> >
> > 4.0 has to use Validate throughout the entire package. NPE and IAE
> indicate a programming error in the client not adhering to the contract
> depicted by the Javadocs, so it is the client's problem to deal with them.
> With proper programming, you should not have to catch those exception at
> all.
> >
> >
> >>> This mail was sent in order to discuss around and make decisions to
> solve
> >>> this dilemma where the Java official specification says X and the
> Apache
> >>> official specification says Y.
> >>>
> >>
> >> Can you please provide a lnk to the official specification you're
> refering
> >> to? ;-)
> >
> >
> > Read Effective Java on exceptions. Thiago provided a URL in the JIRA
> issue.
> >
> > Further good resources:
> >
> > 1.
>
> http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> > 2.
> http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
> "One case where it is common practice to throw a RuntimeException is when
> the user calls a method incorrectly. For example, a method can check if one
> of its arguments is incorrectly null. If an argument is null, the method
> might throw a NullPointerException, which is an unchecked exception."
> >
> > Michael
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

sebb-2-2
On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
> This is not a matter of law. If Oracle/Sun set a direction on how to use
> NPE, it's a really good idea to follow them -- even if you don't agree, do
> it for the sake of consistency. I don't think using IAE is somehow "better"
> Java than what they are doing. And I give weight to what Joshua said
> because he's a former architect of that company. Lang3 was designed to
> throw NPE on invalid null arguments because that's what the gurus, like he,
> in our industry who publish "best practices" say it should. If your opinion
> bears greater weight than those set forth the best practices, then you win,
> but I don't advocate going back to IAE for nulls for the reasons stated.

The problem is still that NPE can be thrown by the JVM for code bugs.
If you Google/Bing for "what does NPE mean?" most of the postings say
that this is due to a bug in the code that throws it rather than a bug
in the code that calls it.

There is nothing inherently wrong with using IAE for reporting a null argument.
I think it was a mistake to suggest using NPE for that.
One might as well throw ArithmeticException for a zero argument that
is going to be used as a divisor.
Neither is as helpful as IAE.

The problem is that NPE is ambiguous. IAE is not.

>
>
>
> Cheers,
> Paul
>
>
> On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]> wrote:
>
>> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
>> >
>> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
>> >
>> >> Hi Thiago,
>> >>
>> >>
>> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>> >>
>> >>> Hello people,
>> >>>
>> >>> Analizing the JIRA issue
>> https://issues.apache.org/jira/browse/LANG-1008the
>> >>> contributors noticed that NumberUtils.max/min methods all have the same
>> >>> problem:
>> >>> They all throw an IllegalArgumentException when according to the
>> official
>> >>> documentation (Oracle|Sun) says that a NullPointerException must be
>> thrown
>> >>> when an argument must not be null.
>> >>>
>> >>
>> >> This is not a problem imho. It is a question of API design. I don't now
>> an
>> >> offical documentation that say when IAE or NPE _must_ be thrown.
>> Sun/Oracle
>> >> at some point decided to throw NPE when ever a null reference is passed
>> to
>> >> a method that doesn't accept null inputs. I don't feel this is right,
>> since
>> >> a null input is also an illegal argument. Why make a differenciation?
>> IMHO
>> >> NPE should be reserved to the JVM, when a method is called on a null
>> >> reference, but that's just my opinion.
>> >
>> >
>> > It *is* a problem because NullPointerException and
>> IllegalArgumentException have concrete semantics layed out in the JDK's
>> Javadocs. If you see how both are used in the JDK, you see that NPE and IAE
>> are used properly and there is no such restriction to the JDK only. If you
>> aread Effective Java, you'll see that you *have to* use NPE if a null
>> argument is passed. One might remember the NullArgumentException back in
>> Lang 2, it was removed because it is imperative to use NPE instead.
>>
>> Effective Java is a great book, but don't confuse Joshua's advice with law.
>>
>> >
>> > Moreover, the Lang 3 package includes a great class, Validate, which does
>> things right and now I can ask, why the hell is that not used throughout
>> the entire library?
>>
>> +1 to this. We should update all of lang to use Validate once we've nailed
>> this issue.
>>
>> Duncan
>>
>> >
>> >
>> >>> However according to Apache Commons Lang Developer Guide, these methods
>> are
>> >>> all correct. This guide says that "When throwing an exception to
>> indicate a
>> >>> bad argument, always try to throw IllegalArgumentException, even if the
>> >>> argument was null. Do not throw NullPointerException.".
>> >
>> >
>> > Correct to the dev guide only -- not Java.
>> >
>> >
>> >> Since [lang] is currently designed this way, I'd rather deal with this
>> >> issue for 4.0. We can then revisit our initial decision to only throw
>> IAE
>> >> an maybe align it to what the JDK now does. If you want to file an
>> issue,
>> >> my opinion is, that it should be fix version 4.0. Changing the
>> exceptions
>> >> that are thrown now may break clients (although I think there are very
>> few
>> >> use cases where one should catch IAE or NPE).
>> >
>> >
>> > 4.0 has to use Validate throughout the entire package. NPE and IAE
>> indicate a programming error in the client not adhering to the contract
>> depicted by the Javadocs, so it is the client's problem to deal with them.
>> With proper programming, you should not have to catch those exception at
>> all.
>> >
>> >
>> >>> This mail was sent in order to discuss around and make decisions to
>> solve
>> >>> this dilemma where the Java official specification says X and the
>> Apache
>> >>> official specification says Y.
>> >>>
>> >>
>> >> Can you please provide a lnk to the official specification you're
>> refering
>> >> to? ;-)
>> >
>> >
>> > Read Effective Java on exceptions. Thiago provided a URL in the JIRA
>> issue.
>> >
>> > Further good resources:
>> >
>> > 1.
>>
>> http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
>> > 2.
>> http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
>> "One case where it is common practice to throw a RuntimeException is when
>> the user calls a method incorrectly. For example, a method can check if one
>> of its arguments is incorrectly null. If an argument is null, the method
>> might throw a NullPointerException, which is an unchecked exception."
>> >
>> > Michael
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [hidden email]
>> > For additional commands, e-mail: [hidden email]
>> >
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Paul Benedict
When you dereference a null pointer, you get an NPE. We can agree to that.
We can also agree it's not inherently wrong to throw IAE on a null argument
check, but this discussion has never been about that. The discussion has
always centered on what the trend setters are doing -- and they say go with
NPE.

Oracle/Sun throws NPE in its method:
http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T%29

Google Guava throws NPE in its method:
http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html#checkNotNull%28T%29

It's pretty clear where industry is going and not using NPE is not
expected. We shouldn't try to resist where all the thought leaders in our
industry are going. It doesn't make any sense. No matter what personal
affinity/preference you have towards IAE, it's a losing battle because the
march is going the other direction.

Paul


Cheers,
Paul


On Tue, May 6, 2014 at 6:27 PM, sebb <[hidden email]> wrote:

> On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
> > This is not a matter of law. If Oracle/Sun set a direction on how to use
> > NPE, it's a really good idea to follow them -- even if you don't agree,
> do
> > it for the sake of consistency. I don't think using IAE is somehow
> "better"
> > Java than what they are doing. And I give weight to what Joshua said
> > because he's a former architect of that company. Lang3 was designed to
> > throw NPE on invalid null arguments because that's what the gurus, like
> he,
> > in our industry who publish "best practices" say it should. If your
> opinion
> > bears greater weight than those set forth the best practices, then you
> win,
> > but I don't advocate going back to IAE for nulls for the reasons stated.
>
> The problem is still that NPE can be thrown by the JVM for code bugs.
> If you Google/Bing for "what does NPE mean?" most of the postings say
> that this is due to a bug in the code that throws it rather than a bug
> in the code that calls it.
>
> There is nothing inherently wrong with using IAE for reporting a null
> argument.
> I think it was a mistake to suggest using NPE for that.
> One might as well throw ArithmeticException for a zero argument that
> is going to be used as a divisor.
> Neither is as helpful as IAE.
>
> The problem is that NPE is ambiguous. IAE is not.
>
> >
> >
> >
> > Cheers,
> > Paul
> >
> >
> > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]>
> wrote:
> >
> >> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
> >> >
> >> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
> >> >
> >> >> Hi Thiago,
> >> >>
> >> >>
> >> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >> >>
> >> >>> Hello people,
> >> >>>
> >> >>> Analizing the JIRA issue
> >> https://issues.apache.org/jira/browse/LANG-1008the
> >> >>> contributors noticed that NumberUtils.max/min methods all have the
> same
> >> >>> problem:
> >> >>> They all throw an IllegalArgumentException when according to the
> >> official
> >> >>> documentation (Oracle|Sun) says that a NullPointerException must be
> >> thrown
> >> >>> when an argument must not be null.
> >> >>>
> >> >>
> >> >> This is not a problem imho. It is a question of API design. I don't
> now
> >> an
> >> >> offical documentation that say when IAE or NPE _must_ be thrown.
> >> Sun/Oracle
> >> >> at some point decided to throw NPE when ever a null reference is
> passed
> >> to
> >> >> a method that doesn't accept null inputs. I don't feel this is right,
> >> since
> >> >> a null input is also an illegal argument. Why make a differenciation?
> >> IMHO
> >> >> NPE should be reserved to the JVM, when a method is called on a null
> >> >> reference, but that's just my opinion.
> >> >
> >> >
> >> > It *is* a problem because NullPointerException and
> >> IllegalArgumentException have concrete semantics layed out in the JDK's
> >> Javadocs. If you see how both are used in the JDK, you see that NPE and
> IAE
> >> are used properly and there is no such restriction to the JDK only. If
> you
> >> aread Effective Java, you'll see that you *have to* use NPE if a null
> >> argument is passed. One might remember the NullArgumentException back in
> >> Lang 2, it was removed because it is imperative to use NPE instead.
> >>
> >> Effective Java is a great book, but don't confuse Joshua's advice with
> law.
> >>
> >> >
> >> > Moreover, the Lang 3 package includes a great class, Validate, which
> does
> >> things right and now I can ask, why the hell is that not used throughout
> >> the entire library?
> >>
> >> +1 to this. We should update all of lang to use Validate once we've
> nailed
> >> this issue.
> >>
> >> Duncan
> >>
> >> >
> >> >
> >> >>> However according to Apache Commons Lang Developer Guide, these
> methods
> >> are
> >> >>> all correct. This guide says that "When throwing an exception to
> >> indicate a
> >> >>> bad argument, always try to throw IllegalArgumentException, even if
> the
> >> >>> argument was null. Do not throw NullPointerException.".
> >> >
> >> >
> >> > Correct to the dev guide only -- not Java.
> >> >
> >> >
> >> >> Since [lang] is currently designed this way, I'd rather deal with
> this
> >> >> issue for 4.0. We can then revisit our initial decision to only throw
> >> IAE
> >> >> an maybe align it to what the JDK now does. If you want to file an
> >> issue,
> >> >> my opinion is, that it should be fix version 4.0. Changing the
> >> exceptions
> >> >> that are thrown now may break clients (although I think there are
> very
> >> few
> >> >> use cases where one should catch IAE or NPE).
> >> >
> >> >
> >> > 4.0 has to use Validate throughout the entire package. NPE and IAE
> >> indicate a programming error in the client not adhering to the contract
> >> depicted by the Javadocs, so it is the client's problem to deal with
> them.
> >> With proper programming, you should not have to catch those exception at
> >> all.
> >> >
> >> >
> >> >>> This mail was sent in order to discuss around and make decisions to
> >> solve
> >> >>> this dilemma where the Java official specification says X and the
> >> Apache
> >> >>> official specification says Y.
> >> >>>
> >> >>
> >> >> Can you please provide a lnk to the official specification you're
> >> refering
> >> >> to? ;-)
> >> >
> >> >
> >> > Read Effective Java on exceptions. Thiago provided a URL in the JIRA
> >> issue.
> >> >
> >> > Further good resources:
> >> >
> >> > 1.
> >>
> >>
> http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> >> > 2.
> >>
> http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
> >> "One case where it is common practice to throw a RuntimeException is
> when
> >> the user calls a method incorrectly. For example, a method can check if
> one
> >> of its arguments is incorrectly null. If an argument is null, the method
> >> might throw a NullPointerException, which is an unchecked exception."
> >> >
> >> > Michael
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: [hidden email]
> >> > For additional commands, e-mail: [hidden email]
> >> >
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

sebb-2-2
On 7 May 2014 01:51, Paul Benedict <[hidden email]> wrote:

> When you dereference a null pointer, you get an NPE. We can agree to that.
> We can also agree it's not inherently wrong to throw IAE on a null argument
> check, but this discussion has never been about that. The discussion has
> always centered on what the trend setters are doing -- and they say go with
> NPE.
>
> Oracle/Sun throws NPE in its method:
> http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T%29
>
> Google Guava throws NPE in its method:
> http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html#checkNotNull%28T%29
>
> It's pretty clear where industry is going and not using NPE is not
> expected. We shouldn't try to resist where all the thought leaders in our
> industry are going. It doesn't make any sense. No matter what personal
> affinity/preference you have towards IAE, it's a losing battle because the
> march is going the other direction.

None of that alters the fact the using NPE in this way is ambiguous.
Whereas IAE is not.

> Paul
>
>
> Cheers,
> Paul
>
>
> On Tue, May 6, 2014 at 6:27 PM, sebb <[hidden email]> wrote:
>
>> On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
>> > This is not a matter of law. If Oracle/Sun set a direction on how to use
>> > NPE, it's a really good idea to follow them -- even if you don't agree,
>> do
>> > it for the sake of consistency. I don't think using IAE is somehow
>> "better"
>> > Java than what they are doing. And I give weight to what Joshua said
>> > because he's a former architect of that company. Lang3 was designed to
>> > throw NPE on invalid null arguments because that's what the gurus, like
>> he,
>> > in our industry who publish "best practices" say it should. If your
>> opinion
>> > bears greater weight than those set forth the best practices, then you
>> win,
>> > but I don't advocate going back to IAE for nulls for the reasons stated.
>>
>> The problem is still that NPE can be thrown by the JVM for code bugs.
>> If you Google/Bing for "what does NPE mean?" most of the postings say
>> that this is due to a bug in the code that throws it rather than a bug
>> in the code that calls it.
>>
>> There is nothing inherently wrong with using IAE for reporting a null
>> argument.
>> I think it was a mistake to suggest using NPE for that.
>> One might as well throw ArithmeticException for a zero argument that
>> is going to be used as a divisor.
>> Neither is as helpful as IAE.
>>
>> The problem is that NPE is ambiguous. IAE is not.
>>
>> >
>> >
>> >
>> > Cheers,
>> > Paul
>> >
>> >
>> > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]>
>> wrote:
>> >
>> >> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
>> >> >
>> >> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
>> >> >
>> >> >> Hi Thiago,
>> >> >>
>> >> >>
>> >> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
>> >> >>
>> >> >>> Hello people,
>> >> >>>
>> >> >>> Analizing the JIRA issue
>> >> https://issues.apache.org/jira/browse/LANG-1008the
>> >> >>> contributors noticed that NumberUtils.max/min methods all have the
>> same
>> >> >>> problem:
>> >> >>> They all throw an IllegalArgumentException when according to the
>> >> official
>> >> >>> documentation (Oracle|Sun) says that a NullPointerException must be
>> >> thrown
>> >> >>> when an argument must not be null.
>> >> >>>
>> >> >>
>> >> >> This is not a problem imho. It is a question of API design. I don't
>> now
>> >> an
>> >> >> offical documentation that say when IAE or NPE _must_ be thrown.
>> >> Sun/Oracle
>> >> >> at some point decided to throw NPE when ever a null reference is
>> passed
>> >> to
>> >> >> a method that doesn't accept null inputs. I don't feel this is right,
>> >> since
>> >> >> a null input is also an illegal argument. Why make a differenciation?
>> >> IMHO
>> >> >> NPE should be reserved to the JVM, when a method is called on a null
>> >> >> reference, but that's just my opinion.
>> >> >
>> >> >
>> >> > It *is* a problem because NullPointerException and
>> >> IllegalArgumentException have concrete semantics layed out in the JDK's
>> >> Javadocs. If you see how both are used in the JDK, you see that NPE and
>> IAE
>> >> are used properly and there is no such restriction to the JDK only. If
>> you
>> >> aread Effective Java, you'll see that you *have to* use NPE if a null
>> >> argument is passed. One might remember the NullArgumentException back in
>> >> Lang 2, it was removed because it is imperative to use NPE instead.
>> >>
>> >> Effective Java is a great book, but don't confuse Joshua's advice with
>> law.
>> >>
>> >> >
>> >> > Moreover, the Lang 3 package includes a great class, Validate, which
>> does
>> >> things right and now I can ask, why the hell is that not used throughout
>> >> the entire library?
>> >>
>> >> +1 to this. We should update all of lang to use Validate once we've
>> nailed
>> >> this issue.
>> >>
>> >> Duncan
>> >>
>> >> >
>> >> >
>> >> >>> However according to Apache Commons Lang Developer Guide, these
>> methods
>> >> are
>> >> >>> all correct. This guide says that "When throwing an exception to
>> >> indicate a
>> >> >>> bad argument, always try to throw IllegalArgumentException, even if
>> the
>> >> >>> argument was null. Do not throw NullPointerException.".
>> >> >
>> >> >
>> >> > Correct to the dev guide only -- not Java.
>> >> >
>> >> >
>> >> >> Since [lang] is currently designed this way, I'd rather deal with
>> this
>> >> >> issue for 4.0. We can then revisit our initial decision to only throw
>> >> IAE
>> >> >> an maybe align it to what the JDK now does. If you want to file an
>> >> issue,
>> >> >> my opinion is, that it should be fix version 4.0. Changing the
>> >> exceptions
>> >> >> that are thrown now may break clients (although I think there are
>> very
>> >> few
>> >> >> use cases where one should catch IAE or NPE).
>> >> >
>> >> >
>> >> > 4.0 has to use Validate throughout the entire package. NPE and IAE
>> >> indicate a programming error in the client not adhering to the contract
>> >> depicted by the Javadocs, so it is the client's problem to deal with
>> them.
>> >> With proper programming, you should not have to catch those exception at
>> >> all.
>> >> >
>> >> >
>> >> >>> This mail was sent in order to discuss around and make decisions to
>> >> solve
>> >> >>> this dilemma where the Java official specification says X and the
>> >> Apache
>> >> >>> official specification says Y.
>> >> >>>
>> >> >>
>> >> >> Can you please provide a lnk to the official specification you're
>> >> refering
>> >> >> to? ;-)
>> >> >
>> >> >
>> >> > Read Effective Java on exceptions. Thiago provided a URL in the JIRA
>> >> issue.
>> >> >
>> >> > Further good resources:
>> >> >
>> >> > 1.
>> >>
>> >>
>> http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
>> >> > 2.
>> >>
>> http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
>> >> "One case where it is common practice to throw a RuntimeException is
>> when
>> >> the user calls a method incorrectly. For example, a method can check if
>> one
>> >> of its arguments is incorrectly null. If an argument is null, the method
>> >> might throw a NullPointerException, which is an unchecked exception."
>> >> >
>> >> > Michael
>> >> >
>> >> >
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: [hidden email]
>> >> > For additional commands, e-mail: [hidden email]
>> >> >
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [lang]

garydgregory
In reply to this post by Duncan Jones
On Tue, May 6, 2014 at 4:50 PM, Duncan Jones <[hidden email]> wrote:

> On 6 May 2014 19:19, Paul Benedict <[hidden email]> wrote:
> > NPE is implicit if the method does not allow an argument to be null. This
> > doesn't have to be the case. This has nothing to do with the JDK vs. 3rd
> > party source. It's just about the contract. As long as you document which
> > arguments can be null, then you're good -- otherwise throw an NPE to
> > capture the contract violation.
> >
> >
> > Cheers,
> > Paul
>
> I'm strongly in favour of IAE for incorrect null inputs. It makes it
> completely clear that the input was validated and found to be lacking.
> A NPE tends to make me think something unanticipated has happened.
>

+1


>
> I agree with Sebb: NPEs will have people blaming the library before
> their own code.
>

+1

Gary


>
> Duncan
>
>
> >
> >
> > On Tue, May 6, 2014 at 12:09 PM, sebb <[hidden email]> wrote:
> >
> >> On 6 May 2014 14:27, Benedikt Ritter <[hidden email]> wrote:
> >> > Hi Thiago,
> >> >
> >> >
> >> > 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >> >
> >> >> Hello people,
> >> >>
> >> >> Analizing the JIRA issue
> >> https://issues.apache.org/jira/browse/LANG-1008the
> >> >> contributors noticed that NumberUtils.max/min methods all have the
> same
> >> >> problem:
> >> >> They all throw an IllegalArgumentException when according to the
> >> official
> >> >> documentation (Oracle|Sun) says that a NullPointerException must be
> >> thrown
> >> >> when an argument must not be null.
> >> >>
> >> >
> >> > This is not a problem imho. It is a question of API design.
> >>
> >> +1
> >>
> >> > I don't now an
> >> > offical documentation that say when IAE or NPE _must_ be thrown.
> >> Sun/Oracle
> >> > at some point decided to throw NPE when ever a null reference is
> passed
> >> to
> >> > a method that doesn't accept null inputs. I don't feel this is right,
> >> since
> >> > a null input is also an illegal argument. Why make a differenciation?
> >> IMHO
> >> > NPE should be reserved to the JVM, when a method is called on a null
> >> > reference, but that's just my opinion.
> >> >
> >>
> >> +1.
> >>
> >> NPE used to mean a bug had occurred rather than the user had provided
> bad
> >> input.
> >>
> >> Using NPE for a parameter that must not be null confuses things.
> >>
> >> >
> >> >>
> >> >> However according to Apache Commons Lang Developer Guide, these
> methods
> >> are
> >> >> all correct. This guide says that "When throwing an exception to
> >> indicate a
> >> >> bad argument, always try to throw IllegalArgumentException, even if
> the
> >> >> argument was null. Do not throw NullPointerException.".
> >> >>
> >> >
> >> > Since [lang] is currently designed this way, I'd rather deal with this
> >> > issue for 4.0. We can then revisit our initial decision to only throw
> IAE
> >> > an maybe align it to what the JDK now does. If you want to file an
> issue,
> >> > my opinion is, that it should be fix version 4.0. Changing the
> exceptions
> >> > that are thrown now may break clients (although I think there are very
> >> few
> >> > use cases where one should catch IAE or NPE).
> >>
> >> If Commons ever decide to switch to NPE (I hope not) then it is
> >> imperative that the message is 100% clear that the problem is with  a
> >> method argument, and which argument is at fault.
> >>
> >> Otherwise we will likely find ourselves fielding bug reports about
> >> Commons code when it is the caller that is at fault.
> >> Even then, I suspect some reporters will just see the NPE and assume
> >> that the Commons code has a bug.
> >>
> >> If an argument is invalid, throw IAE.
> >> IMO it does not make sense to throw NPE for some invalid arguments and
> >> not others.
> >> What Sun/Oracle perhaps should have done was introduce an
> >> "InvalidNullArgumentException"
> >>
> >> The Javadoc (1.7) says:
> >>
> >> >>>
> >> Thrown when an application attempts to use null in a case where an
> >> object is required. These include:
> >>
> >> Calling the instance method of a null object.
> >> Accessing or modifying the field of a null object.
> >> Taking the length of null as if it were an array.
> >> Accessing or modifying the slots of null as if it were an array.
> >> Throwing null as if it were a Throwable value.
> >>
> >> Applications should throw instances of this class to indicate other
> >> illegal uses of the null object.
> >> <<<
> >>
> >> I suppose "illegal use of the null object" could be taken to mean
> >> passing null to a non-nullable parameter, but I think that is
> >> stretching it too far.
> >>
> >> >
> >> >>
> >> >> This mail was sent in order to discuss around and make decisions to
> >> solve
> >> >> this dilemma where the Java official specification says X and the
> Apache
> >> >> official specification says Y.
> >> >>
> >> >
> >> > Can you please provide a lnk to the official specification you're
> >> refering
> >> > to? ;-)
> >> >
> >> > Regards,
> >> > Benedikt
> >> >
> >> >
> >> >>
> >> >> My sincere thanks for your time and consideration,
> >> >>
> >> >> --
> >> >> Thiago Andrade
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > http://people.apache.org/~britter/
> >> > http://www.systemoutprintln.de/
> >> > http://twitter.com/BenediktRitter
> >> > http://github.com/britter
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Duncan Jones
In reply to this post by Paul Benedict
On 7 May 2014 01:52, "Paul Benedict" <[hidden email]> wrote:
>
> When you dereference a null pointer, you get an NPE. We can agree to that.
> We can also agree it's not inherently wrong to throw IAE on a null
argument
> check, but this discussion has never been about that. The discussion has
> always centered on what the trend setters are doing -- and they say go
with
> NPE.
>
> Oracle/Sun throws NPE in its method:
>
http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T%29
>
> Google Guava throws NPE in its method:
>
http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html#checkNotNull%28T%29
>
> It's pretty clear where industry is going and not using NPE is not
> expected. We shouldn't try to resist where all the thought leaders in our
> industry are going. It doesn't make any sense. No matter what personal
> affinity/preference you have towards IAE, it's a losing battle because the
> march is going the other direction.

This is a very compelling point. We don't want to alienate our user base
because a handful of us believe the Java community is going in the wrong
direction.

I could be swayed by that argument alone. We hardly need more reasons for
people to consider Lang to be outdated compared with Guava etc.

>
> Paul
>
>
> Cheers,
> Paul
>
>
> On Tue, May 6, 2014 at 6:27 PM, sebb <[hidden email]> wrote:
>
> > On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
> > > This is not a matter of law. If Oracle/Sun set a direction on how to
use
> > > NPE, it's a really good idea to follow them -- even if you don't
agree,
> > do
> > > it for the sake of consistency. I don't think using IAE is somehow
> > "better"
> > > Java than what they are doing. And I give weight to what Joshua said
> > > because he's a former architect of that company. Lang3 was designed to
> > > throw NPE on invalid null arguments because that's what the gurus,
like
> > he,
> > > in our industry who publish "best practices" say it should. If your
> > opinion
> > > bears greater weight than those set forth the best practices, then you
> > win,
> > > but I don't advocate going back to IAE for nulls for the reasons
stated.

> >
> > The problem is still that NPE can be thrown by the JVM for code bugs.
> > If you Google/Bing for "what does NPE mean?" most of the postings say
> > that this is due to a bug in the code that throws it rather than a bug
> > in the code that calls it.
> >
> > There is nothing inherently wrong with using IAE for reporting a null
> > argument.
> > I think it was a mistake to suggest using NPE for that.
> > One might as well throw ArithmeticException for a zero argument that
> > is going to be used as a divisor.
> > Neither is as helpful as IAE.
> >
> > The problem is that NPE is ambiguous. IAE is not.
> >
> > >
> > >
> > >
> > > Cheers,
> > > Paul
> > >
> > >
> > > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]>
> > wrote:
> > >
> > >> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
> > >> >
> > >> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
> > >> >
> > >> >> Hi Thiago,
> > >> >>
> > >> >>
> > >> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> > >> >>
> > >> >>> Hello people,
> > >> >>>
> > >> >>> Analizing the JIRA issue
> > >> https://issues.apache.org/jira/browse/LANG-1008the
> > >> >>> contributors noticed that NumberUtils.max/min methods all have
the
> > same
> > >> >>> problem:
> > >> >>> They all throw an IllegalArgumentException when according to the
> > >> official
> > >> >>> documentation (Oracle|Sun) says that a NullPointerException must
be
> > >> thrown
> > >> >>> when an argument must not be null.
> > >> >>>
> > >> >>
> > >> >> This is not a problem imho. It is a question of API design. I
don't
> > now
> > >> an
> > >> >> offical documentation that say when IAE or NPE _must_ be thrown.
> > >> Sun/Oracle
> > >> >> at some point decided to throw NPE when ever a null reference is
> > passed
> > >> to
> > >> >> a method that doesn't accept null inputs. I don't feel this is
right,
> > >> since
> > >> >> a null input is also an illegal argument. Why make a
differenciation?
> > >> IMHO
> > >> >> NPE should be reserved to the JVM, when a method is called on a
null
> > >> >> reference, but that's just my opinion.
> > >> >
> > >> >
> > >> > It *is* a problem because NullPointerException and
> > >> IllegalArgumentException have concrete semantics layed out in the
JDK's
> > >> Javadocs. If you see how both are used in the JDK, you see that NPE
and
> > IAE
> > >> are used properly and there is no such restriction to the JDK only.
If
> > you
> > >> aread Effective Java, you'll see that you *have to* use NPE if a null
> > >> argument is passed. One might remember the NullArgumentException
back in
> > >> Lang 2, it was removed because it is imperative to use NPE instead.
> > >>
> > >> Effective Java is a great book, but don't confuse Joshua's advice
with
> > law.
> > >>
> > >> >
> > >> > Moreover, the Lang 3 package includes a great class, Validate,
which
> > does
> > >> things right and now I can ask, why the hell is that not used
throughout

> > >> the entire library?
> > >>
> > >> +1 to this. We should update all of lang to use Validate once we've
> > nailed
> > >> this issue.
> > >>
> > >> Duncan
> > >>
> > >> >
> > >> >
> > >> >>> However according to Apache Commons Lang Developer Guide, these
> > methods
> > >> are
> > >> >>> all correct. This guide says that "When throwing an exception to
> > >> indicate a
> > >> >>> bad argument, always try to throw IllegalArgumentException, even
if

> > the
> > >> >>> argument was null. Do not throw NullPointerException.".
> > >> >
> > >> >
> > >> > Correct to the dev guide only -- not Java.
> > >> >
> > >> >
> > >> >> Since [lang] is currently designed this way, I'd rather deal with
> > this
> > >> >> issue for 4.0. We can then revisit our initial decision to only
throw

> > >> IAE
> > >> >> an maybe align it to what the JDK now does. If you want to file an
> > >> issue,
> > >> >> my opinion is, that it should be fix version 4.0. Changing the
> > >> exceptions
> > >> >> that are thrown now may break clients (although I think there are
> > very
> > >> few
> > >> >> use cases where one should catch IAE or NPE).
> > >> >
> > >> >
> > >> > 4.0 has to use Validate throughout the entire package. NPE and IAE
> > >> indicate a programming error in the client not adhering to the
contract
> > >> depicted by the Javadocs, so it is the client's problem to deal with
> > them.
> > >> With proper programming, you should not have to catch those
exception at
> > >> all.
> > >> >
> > >> >
> > >> >>> This mail was sent in order to discuss around and make decisions
to

> > >> solve
> > >> >>> this dilemma where the Java official specification says X and the
> > >> Apache
> > >> >>> official specification says Y.
> > >> >>>
> > >> >>
> > >> >> Can you please provide a lnk to the official specification you're
> > >> refering
> > >> >> to? ;-)
> > >> >
> > >> >
> > >> > Read Effective Java on exceptions. Thiago provided a URL in the
JIRA
> > >> issue.
> > >> >
> > >> > Further good resources:
> > >> >
> > >> > 1.
> > >>
> > >>
> >
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> > >> > 2.
> > >>
> > http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html
:
> > >> "One case where it is common practice to throw a RuntimeException is
> > when
> > >> the user calls a method incorrectly. For example, a method can check
if
> > one
> > >> of its arguments is incorrectly null. If an argument is null, the
method
> > >> might throw a NullPointerException, which is an unchecked exception."
> > >> >
> > >> > Michael
> > >> >
> > >> >
> > >> >
> > >> >
---------------------------------------------------------------------

> > >> > To unsubscribe, e-mail: [hidden email]
> > >> > For additional commands, e-mail: [hidden email]
> > >> >
> > >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

Duncan Jones
In reply to this post by sebb-2-2
On 7 May 2014 21:07, "sebb" <[hidden email]> wrote:
>
> On 7 May 2014 01:51, Paul Benedict <[hidden email]> wrote:
> > When you dereference a null pointer, you get an NPE. We can agree to
that.
> > We can also agree it's not inherently wrong to throw IAE on a null
argument
> > check, but this discussion has never been about that. The discussion has
> > always centered on what the trend setters are doing -- and they say go
with
> > NPE.
> >
> > Oracle/Sun throws NPE in its method:
> >
http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T%29
> >
> > Google Guava throws NPE in its method:
> >
http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html#checkNotNull%28T%29
> >
> > It's pretty clear where industry is going and not using NPE is not
> > expected. We shouldn't try to resist where all the thought leaders in
our
> > industry are going. It doesn't make any sense. No matter what personal
> > affinity/preference you have towards IAE, it's a losing battle because
the
> > march is going the other direction.
>
> None of that alters the fact the using NPE in this way is ambiguous.
> Whereas IAE is not.

Yes but is this a discussion about what is correct or what we should do in
Lang?

I think the two are not necessarily the same (sadly) and that the focus is
on the latter. Hence Paul's comment has merit.

>
> > Paul
> >
> >
> > Cheers,
> > Paul
> >
> >
> > On Tue, May 6, 2014 at 6:27 PM, sebb <[hidden email]> wrote:
> >
> >> On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
> >> > This is not a matter of law. If Oracle/Sun set a direction on how to
use
> >> > NPE, it's a really good idea to follow them -- even if you don't
agree,
> >> do
> >> > it for the sake of consistency. I don't think using IAE is somehow
> >> "better"
> >> > Java than what they are doing. And I give weight to what Joshua said
> >> > because he's a former architect of that company. Lang3 was designed
to
> >> > throw NPE on invalid null arguments because that's what the gurus,
like
> >> he,
> >> > in our industry who publish "best practices" say it should. If your
> >> opinion
> >> > bears greater weight than those set forth the best practices, then
you
> >> win,
> >> > but I don't advocate going back to IAE for nulls for the reasons
stated.

> >>
> >> The problem is still that NPE can be thrown by the JVM for code bugs.
> >> If you Google/Bing for "what does NPE mean?" most of the postings say
> >> that this is due to a bug in the code that throws it rather than a bug
> >> in the code that calls it.
> >>
> >> There is nothing inherently wrong with using IAE for reporting a null
> >> argument.
> >> I think it was a mistake to suggest using NPE for that.
> >> One might as well throw ArithmeticException for a zero argument that
> >> is going to be used as a divisor.
> >> Neither is as helpful as IAE.
> >>
> >> The problem is that NPE is ambiguous. IAE is not.
> >>
> >> >
> >> >
> >> >
> >> > Cheers,
> >> > Paul
> >> >
> >> >
> >> > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]>
> >> wrote:
> >> >
> >> >> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
> >> >> >
> >> >> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
> >> >> >
> >> >> >> Hi Thiago,
> >> >> >>
> >> >> >>
> >> >> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >> >> >>
> >> >> >>> Hello people,
> >> >> >>>
> >> >> >>> Analizing the JIRA issue
> >> >> https://issues.apache.org/jira/browse/LANG-1008the
> >> >> >>> contributors noticed that NumberUtils.max/min methods all have
the
> >> same
> >> >> >>> problem:
> >> >> >>> They all throw an IllegalArgumentException when according to the
> >> >> official
> >> >> >>> documentation (Oracle|Sun) says that a NullPointerException
must be
> >> >> thrown
> >> >> >>> when an argument must not be null.
> >> >> >>>
> >> >> >>
> >> >> >> This is not a problem imho. It is a question of API design. I
don't
> >> now
> >> >> an
> >> >> >> offical documentation that say when IAE or NPE _must_ be thrown.
> >> >> Sun/Oracle
> >> >> >> at some point decided to throw NPE when ever a null reference is
> >> passed
> >> >> to
> >> >> >> a method that doesn't accept null inputs. I don't feel this is
right,
> >> >> since
> >> >> >> a null input is also an illegal argument. Why make a
differenciation?
> >> >> IMHO
> >> >> >> NPE should be reserved to the JVM, when a method is called on a
null
> >> >> >> reference, but that's just my opinion.
> >> >> >
> >> >> >
> >> >> > It *is* a problem because NullPointerException and
> >> >> IllegalArgumentException have concrete semantics layed out in the
JDK's
> >> >> Javadocs. If you see how both are used in the JDK, you see that NPE
and
> >> IAE
> >> >> are used properly and there is no such restriction to the JDK only.
If
> >> you
> >> >> aread Effective Java, you'll see that you *have to* use NPE if a
null
> >> >> argument is passed. One might remember the NullArgumentException
back in
> >> >> Lang 2, it was removed because it is imperative to use NPE instead.
> >> >>
> >> >> Effective Java is a great book, but don't confuse Joshua's advice
with
> >> law.
> >> >>
> >> >> >
> >> >> > Moreover, the Lang 3 package includes a great class, Validate,
which
> >> does
> >> >> things right and now I can ask, why the hell is that not used
throughout

> >> >> the entire library?
> >> >>
> >> >> +1 to this. We should update all of lang to use Validate once we've
> >> nailed
> >> >> this issue.
> >> >>
> >> >> Duncan
> >> >>
> >> >> >
> >> >> >
> >> >> >>> However according to Apache Commons Lang Developer Guide, these
> >> methods
> >> >> are
> >> >> >>> all correct. This guide says that "When throwing an exception to
> >> >> indicate a
> >> >> >>> bad argument, always try to throw IllegalArgumentException,
even if

> >> the
> >> >> >>> argument was null. Do not throw NullPointerException.".
> >> >> >
> >> >> >
> >> >> > Correct to the dev guide only -- not Java.
> >> >> >
> >> >> >
> >> >> >> Since [lang] is currently designed this way, I'd rather deal with
> >> this
> >> >> >> issue for 4.0. We can then revisit our initial decision to only
throw
> >> >> IAE
> >> >> >> an maybe align it to what the JDK now does. If you want to file
an

> >> >> issue,
> >> >> >> my opinion is, that it should be fix version 4.0. Changing the
> >> >> exceptions
> >> >> >> that are thrown now may break clients (although I think there are
> >> very
> >> >> few
> >> >> >> use cases where one should catch IAE or NPE).
> >> >> >
> >> >> >
> >> >> > 4.0 has to use Validate throughout the entire package. NPE and IAE
> >> >> indicate a programming error in the client not adhering to the
contract
> >> >> depicted by the Javadocs, so it is the client's problem to deal with
> >> them.
> >> >> With proper programming, you should not have to catch those
exception at
> >> >> all.
> >> >> >
> >> >> >
> >> >> >>> This mail was sent in order to discuss around and make
decisions to
> >> >> solve
> >> >> >>> this dilemma where the Java official specification says X and
the

> >> >> Apache
> >> >> >>> official specification says Y.
> >> >> >>>
> >> >> >>
> >> >> >> Can you please provide a lnk to the official specification you're
> >> >> refering
> >> >> >> to? ;-)
> >> >> >
> >> >> >
> >> >> > Read Effective Java on exceptions. Thiago provided a URL in the
JIRA
> >> >> issue.
> >> >> >
> >> >> > Further good resources:
> >> >> >
> >> >> > 1.
> >> >>
> >> >>
> >>
http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> >> >> > 2.
> >> >>
> >>
http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
> >> >> "One case where it is common practice to throw a RuntimeException is
> >> when
> >> >> the user calls a method incorrectly. For example, a method can
check if
> >> one
> >> >> of its arguments is incorrectly null. If an argument is null, the
method
> >> >> might throw a NullPointerException, which is an unchecked
exception."
> >> >> >
> >> >> > Michael
> >> >> >
> >> >> >
> >> >> >
> >> >> >
---------------------------------------------------------------------

> >> >> > To unsubscribe, e-mail: [hidden email]
> >> >> > For additional commands, e-mail: [hidden email]
> >> >> >
> >> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: Re: [lang]

garydgregory
In reply to this post by sebb-2-2
On Tue, May 6, 2014 at 9:01 PM, sebb <[hidden email]> wrote:

> On 7 May 2014 01:51, Paul Benedict <[hidden email]> wrote:
> > When you dereference a null pointer, you get an NPE. We can agree to
> that.
> > We can also agree it's not inherently wrong to throw IAE on a null
> argument
> > check, but this discussion has never been about that. The discussion has
> > always centered on what the trend setters are doing -- and they say go
> with
> > NPE.
> >
> > Oracle/Sun throws NPE in its method:
> >
> http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html#requireNonNull%28T%29
> >
> > Google Guava throws NPE in its method:
> >
> http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/base/Preconditions.html#checkNotNull%28T%29
> >
> > It's pretty clear where industry is going and not using NPE is not
> > expected. We shouldn't try to resist where all the thought leaders in our
> > industry are going. It doesn't make any sense. No matter what personal
> > affinity/preference you have towards IAE, it's a losing battle because
> the
> > march is going the other direction.
>
> None of that alters the fact the using NPE in this way is ambiguous.
> Whereas IAE is not.
>

+1.

When I see NPE I think that a real null dereference attempt was caught. An
ISE and IAE clearly state "I detected something illegal".

Gary

>
> > Paul
> >
> >
> > Cheers,
> > Paul
> >
> >
> > On Tue, May 6, 2014 at 6:27 PM, sebb <[hidden email]> wrote:
> >
> >> On 6 May 2014 22:54, Paul Benedict <[hidden email]> wrote:
> >> > This is not a matter of law. If Oracle/Sun set a direction on how to
> use
> >> > NPE, it's a really good idea to follow them -- even if you don't
> agree,
> >> do
> >> > it for the sake of consistency. I don't think using IAE is somehow
> >> "better"
> >> > Java than what they are doing. And I give weight to what Joshua said
> >> > because he's a former architect of that company. Lang3 was designed to
> >> > throw NPE on invalid null arguments because that's what the gurus,
> like
> >> he,
> >> > in our industry who publish "best practices" say it should. If your
> >> opinion
> >> > bears greater weight than those set forth the best practices, then you
> >> win,
> >> > but I don't advocate going back to IAE for nulls for the reasons
> stated.
> >>
> >> The problem is still that NPE can be thrown by the JVM for code bugs.
> >> If you Google/Bing for "what does NPE mean?" most of the postings say
> >> that this is due to a bug in the code that throws it rather than a bug
> >> in the code that calls it.
> >>
> >> There is nothing inherently wrong with using IAE for reporting a null
> >> argument.
> >> I think it was a mistake to suggest using NPE for that.
> >> One might as well throw ArithmeticException for a zero argument that
> >> is going to be used as a divisor.
> >> Neither is as helpful as IAE.
> >>
> >> The problem is that NPE is ambiguous. IAE is not.
> >>
> >> >
> >> >
> >> >
> >> > Cheers,
> >> > Paul
> >> >
> >> >
> >> > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones <[hidden email]>
> >> wrote:
> >> >
> >> >> On 6 May 2014 22:27, "Michael Osipov" <[hidden email]> wrote:
> >> >> >
> >> >> > Am 2014-05-06 15:27, schrieb Benedikt Ritter:
> >> >> >
> >> >> >> Hi Thiago,
> >> >> >>
> >> >> >>
> >> >> >> 2014-05-06 14:53 GMT+02:00 Thiago Andrade <[hidden email]>:
> >> >> >>
> >> >> >>> Hello people,
> >> >> >>>
> >> >> >>> Analizing the JIRA issue
> >> >> https://issues.apache.org/jira/browse/LANG-1008the
> >> >> >>> contributors noticed that NumberUtils.max/min methods all have
> the
> >> same
> >> >> >>> problem:
> >> >> >>> They all throw an IllegalArgumentException when according to the
> >> >> official
> >> >> >>> documentation (Oracle|Sun) says that a NullPointerException must
> be
> >> >> thrown
> >> >> >>> when an argument must not be null.
> >> >> >>>
> >> >> >>
> >> >> >> This is not a problem imho. It is a question of API design. I
> don't
> >> now
> >> >> an
> >> >> >> offical documentation that say when IAE or NPE _must_ be thrown.
> >> >> Sun/Oracle
> >> >> >> at some point decided to throw NPE when ever a null reference is
> >> passed
> >> >> to
> >> >> >> a method that doesn't accept null inputs. I don't feel this is
> right,
> >> >> since
> >> >> >> a null input is also an illegal argument. Why make a
> differenciation?
> >> >> IMHO
> >> >> >> NPE should be reserved to the JVM, when a method is called on a
> null
> >> >> >> reference, but that's just my opinion.
> >> >> >
> >> >> >
> >> >> > It *is* a problem because NullPointerException and
> >> >> IllegalArgumentException have concrete semantics layed out in the
> JDK's
> >> >> Javadocs. If you see how both are used in the JDK, you see that NPE
> and
> >> IAE
> >> >> are used properly and there is no such restriction to the JDK only.
> If
> >> you
> >> >> aread Effective Java, you'll see that you *have to* use NPE if a null
> >> >> argument is passed. One might remember the NullArgumentException
> back in
> >> >> Lang 2, it was removed because it is imperative to use NPE instead.
> >> >>
> >> >> Effective Java is a great book, but don't confuse Joshua's advice
> with
> >> law.
> >> >>
> >> >> >
> >> >> > Moreover, the Lang 3 package includes a great class, Validate,
> which
> >> does
> >> >> things right and now I can ask, why the hell is that not used
> throughout
> >> >> the entire library?
> >> >>
> >> >> +1 to this. We should update all of lang to use Validate once we've
> >> nailed
> >> >> this issue.
> >> >>
> >> >> Duncan
> >> >>
> >> >> >
> >> >> >
> >> >> >>> However according to Apache Commons Lang Developer Guide, these
> >> methods
> >> >> are
> >> >> >>> all correct. This guide says that "When throwing an exception to
> >> >> indicate a
> >> >> >>> bad argument, always try to throw IllegalArgumentException, even
> if
> >> the
> >> >> >>> argument was null. Do not throw NullPointerException.".
> >> >> >
> >> >> >
> >> >> > Correct to the dev guide only -- not Java.
> >> >> >
> >> >> >
> >> >> >> Since [lang] is currently designed this way, I'd rather deal with
> >> this
> >> >> >> issue for 4.0. We can then revisit our initial decision to only
> throw
> >> >> IAE
> >> >> >> an maybe align it to what the JDK now does. If you want to file an
> >> >> issue,
> >> >> >> my opinion is, that it should be fix version 4.0. Changing the
> >> >> exceptions
> >> >> >> that are thrown now may break clients (although I think there are
> >> very
> >> >> few
> >> >> >> use cases where one should catch IAE or NPE).
> >> >> >
> >> >> >
> >> >> > 4.0 has to use Validate throughout the entire package. NPE and IAE
> >> >> indicate a programming error in the client not adhering to the
> contract
> >> >> depicted by the Javadocs, so it is the client's problem to deal with
> >> them.
> >> >> With proper programming, you should not have to catch those
> exception at
> >> >> all.
> >> >> >
> >> >> >
> >> >> >>> This mail was sent in order to discuss around and make decisions
> to
> >> >> solve
> >> >> >>> this dilemma where the Java official specification says X and the
> >> >> Apache
> >> >> >>> official specification says Y.
> >> >> >>>
> >> >> >>
> >> >> >> Can you please provide a lnk to the official specification you're
> >> >> refering
> >> >> >> to? ;-)
> >> >> >
> >> >> >
> >> >> > Read Effective Java on exceptions. Thiago provided a URL in the
> JIRA
> >> >> issue.
> >> >> >
> >> >> > Further good resources:
> >> >> >
> >> >> > 1.
> >> >>
> >> >>
> >>
> http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html
> >> >> > 2.
> >> >>
> >>
> http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html:
> >> >> "One case where it is common practice to throw a RuntimeException is
> >> when
> >> >> the user calls a method incorrectly. For example, a method can check
> if
> >> one
> >> >> of its arguments is incorrectly null. If an argument is null, the
> method
> >> >> might throw a NullPointerException, which is an unchecked exception."
> >> >> >
> >> >> > Michael
> >> >> >
> >> >> >
> >> >> >
> >> >> >
> ---------------------------------------------------------------------
> >> >> > To unsubscribe, e-mail: [hidden email]
> >> >> > For additional commands, e-mail: [hidden email]
> >> >> >
> >> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
E-Mail: [hidden email] | [hidden email]
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
12