The Java documentation is rather lacking in this area.  But I *think* the
standard in Java is to throw NPE, even though it seems a little
counter-intuitive.  I base this off of recent experience using Guava a lot
for precondition checking, and it favors NPE [1], and also Effective Java
[2] which also says to use NPE.

-Stephen

[1] https://code.google.com/p/guava-libraries/wiki/PreconditionsExplained
[2] Effective Java 2nd Edition, Item 60: "Arguably, all erroneous method
invocations boil down to an illegal argument or illegal state, but other
exceptions are standardly used for certain kinds of illegal arguments and
states. If a caller passes null in some parameter for which null values are
prohibited, convention dictates that NullPointerException be thrown rather
than IllegalArgumentException. Similarly, if a caller passes an
out-of-range value in a parameter representing an index into a sequence,
IndexOutOfBoundsException should be thrown rather than
IllegalArgumentException."


On Wed, Jul 31, 2013 at 5:27 PM, Rob Vesse <[email protected]> wrote:

> Isn't IllegalArgumentException actually more appropriate here?
>
> There's a difference between a NPE which is typically something that
> shouldn't have been null being null and an IAE which is used for when
> arguments don't meet the contract of the API which was the case here.
>
> Rob
>
>
> On 7/31/13 2:23 PM, "[email protected]" <[email protected]> wrote:
>
> >Author: sallen
> >Date: Wed Jul 31 21:23:52 2013
> >New Revision: 1509038
> >
> >URL: http://svn.apache.org/r1509038
> >Log:
> >Replace incorrect IllegalArgumentException with a NullPointerException
> >
> >Modified:
> >
> >jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/Up
> >dateWriter.java
> >
> >Modified:
> >jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/Up
> >dateWriter.java
> >URL:
> >
> http://svn.apache.org/viewvc/jena/trunk/jena-arq/src/main/java/com/hp/hpl/
> >jena/sparql/modify/request/UpdateWriter.java?rev=1509038&r1=1509037&r2=150
> >9038&view=diff
> >==========================================================================
> >====
> >---
> >jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/Up
> >dateWriter.java (original)
> >+++
> >jena/trunk/jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/request/Up
> >dateWriter.java Wed Jul 31 21:23:52 2013
> >@@ -58,7 +58,7 @@ public class UpdateWriter implements Clo
> >     public UpdateWriter(IndentedWriter out, SerializationContext sCxt)
> >     {
> >         if (out == null)
> >-            throw new IllegalArgumentException("out may not be null") ;
> >+            throw new NullPointerException("out") ;
> >
> >         // To get legal syntax out, the serialization context
> >         // has to be a bNode mapping that does ??N vars to bNodes
> >
> >
>
>

Reply via email to