Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 3
    Possible duplicate of A very basic question about whether I should check for null and throw NPE? Commented Oct 2, 2016 at 15:18
  • 2
    A stray null can travel a long way from where it was incorrectly passed before blowing up. It's annoying that the java language itself allows all variables to potentially contain null. All methods seems a little excessive but I often put these in while debugging an NPE, having put them in taking them out seems unhelpful Commented Oct 2, 2016 at 15:31
  • @gnat I'd like to get some more opinions; the answers in that question seem to be against the null checks and I'd like to hear some for null checks arguments Commented Oct 2, 2016 at 15:32
  • @RichardTingle With a stack trace do you think that is still a problem? Commented Oct 2, 2016 at 15:34
  • 3
    @Fray yes, stack trace helps sometimes but not always. Imagine a physics engine. setCollisionHandler(null) It may be minutes, perhaps even hours before the NPE occures because the null sits as invalid state until it's exercised, and at that point the stack trace will be for what validly called the handler, not what invalidly put the null in Commented Oct 2, 2016 at 16:23