I have a failed Java library that I inherited that parses JSON. Right now, if you request a key that does not exist in the JSON array, it is dying with a null pointer. I am going to edit the library to make something more reasonable. I think I have two options:
1) Return zero so the caller can check
2) Throw a more explicit exception (more descriptive than the "Null Pointer"), causing the caller to handle the case when they requested a nonexistent key.
I come from a python background and are strongly attached to number 2, seeing that this will ensure that some collar cannot call this function, and then continue with a zero value, knocking down its application later and possibly corrupting the data. What do you think is more in line with Java best practices ? This is not a duplicate of other language-independent questions on the same topic. This is specifically in the context of Java !!!!
source
share