I have an unfortunate Java library that I've inherited that parses JSON. Right now, if you ask for a key that doesn't exist in a JSON array, it dies with a null pointer. I'm going to edit the library to do something more reasonable. I think I have two options:
1) Return null so the caller can check
2) Throw a more explicit exception (more descriptive than "Null Pointer"), forcing the caller to handle the case where they asked for a non-existent key.
I come from a python background and am strongly drawn to number 2, seeing as it will ensure that some bonehead can't call this function and then continue on with a null value, crashing their application later on and possibly corrupting data. Which way do YOU think is more in line with best practices of Java? This is not a duplicate of other language-independent questions on the same topic. This is specifically in the context of Java!!!!