[jdom-interest] malformed URL exception exception in saxbuilder.build due to unreachable URL

Rolf Lear jdom at tuis.net
Sat Feb 11 14:29:47 PST 2012

I prefer NullPointer for null values too. In some limited places it 
makes sense to throw IllegalArgumentException.

My 'habit' in the past (and it is recently changing...) has been to:
- if I actually check for null I throw IllegalArgumentException.
- do not check, and then let Java throw the NPE on de-reference.

Having read some things recently in Effective Java, and also more 
carefully implementing core API's like the Collections API, I am now 
more inclined to do an explicit null check, and throw NullPointerException.

I think in cases like JDOM where the code is open-source, it is less 
critical to validate-for-null in methods because the stack trace on NPE 
is easy to follow through on.... If JDOM was closed source, and people 
got a NPE, they would be (justifiably) peeved, especially because the 
stack trace would be no help for identifying the null reference.

Still the question is whether every parameter should be validated before 
use.... in this case, since the actual null de-reference happens deep in 
the URI code it sort of makes sense to check... especially if we are 
adding a check for an invalid URI...

So, in this case, I think I will do an explicit check-for-null, and 
throw NullPointerException... but in a general case the issue is more 

I also think, in this case, that the issue of having XML content instead 
of a SystemID in build(String) is common enough to do the 
pre-validation.... with a better error message. In general though, I 
think that people misusing the documented API should not expect 
'hand-holding' error messages. GIGO


On 11/02/2012 4:44 PM, Paul Libbrecht wrote:
> I would vote for a NullPointerException with a message that says "Null URI".
> But I note that I generally interpret any NullPointerException as a
> place where a "." is.
> And in the case discussed in this thread, this is far far deep inside.
> paul
> Le 11 févr. 2012 à 22:15, Grzegorz a écrit :
>>     Another validation process that would help when doing XML exploration
>>     (i.e you don't know what is in the data and are trying to find out)
>>     would be to throw an exception of the string is null and not use the
>>     "null pointer" exception.
>> Why not? NullPointerException is designed to handle just that.
>> Regards,
>> Grzegorz
>> _______________________________________________
>> To control your jdom-interest membership:
>> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com

More information about the jdom-interest mailing list