JavaDocs for XPath say that if expr, or the input source are null, you get a NullPointerException. If this was my problem, I would do the getInputSource in a separate statement and check the value for null and would also check the expr for null.
Thanks, I'll make that change too, but I think I also realised (my inexperience showing here) that although non primitive types are Nullable, you can't return "null" from a method. Is this correct? The compiler won't tell you anything is wrong, but at runtime you get these NullPointerExceptions.
Changing my code to throw exception rather than allowing a null return value revealed that an XPathExpression was failing to evaluate, which could (read, will) be down to one of the two things you've mentioned
Originally posted by Chris Corbyn: ...although non primitive types are Nullable, you can't return "null" from a method. Is this correct?
I didn't read the whole discussion above, but no, that is not correct; you can certainly return null from a method - except if the return type of the method is a primitive type. [ August 16, 2007: Message edited by: Jesper Young ]
Just to put closure to this case. InputSource wasn't null, but it was causing the NullPointerException elsewhere. Once data had been read from the InputSource for the first time it prevented any further reading of data (I guess the entire stream gets read) which the XPath stuff didn't like. Using org.w3c.dom.DocumentBuilder in order to turn the InputSource into a complete DOM tree first solved the problem perfectly.
Erm, EDIT | That would be javax.xml.parsers.DocumentBuilder sorry. My bad. [ August 17, 2007: Message edited by: Chris Corbyn ]