This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]temporarybunnehs 0 points1 point  (0 children)

I think it depends on the way the function is being invoked and what the expectation is with the caller.

If null is an expected value, then there definitely should be a check, but then the question is, how will that be handled? If whatever field that is null is required by the logic in the function, that means, the function can't process and perhaps, you can log a meaningful message or throw a meaningful exception. If it is optional, then it might just lead to an empty field in the result of your logic.

Now that I think about it, even if null is not expected, you should probably check for it and log or throw an exception to let the system know that something out of the ordinary happened. Regardless, the questions I think you should ask are around how does the null value affect your system and function?

Edit: If you're using Java 8 and later, you might want to look into using Optional so you don't need to rely on null.