11

This question pretty much sums up NullPointerExceptions and how to solve them for almost all cases. Many new questions on NPEs are frequently closed as duplicates of this one.

Because of this, it seems like there shouldn't even be enough unique questions to have a tag. After all, if every NPE question is a duplicate of this one, how could we have enough unique questions to populate it? If not, at what point should a question be considered a duplicate of the one above? Where do we draw the line?

I'm asking because it seems like several questions about NPEs are closed as dupes, but it's not exactly clear why some are but some aren't. Could someone please clarify this matter?

1
  • 2
    I prepared a similar question, but did not post it: When the reason for several questions is the same on an abstract level, it is not clear whether to consider them as duplicates. My question referred to a general lack of understanding of references in Java, and particularly aimed at how to identify the "root question" that they all could be duplicates of. Although only being about NPE, this question is somewhat similar: Where to draw the line? - Or: How much effort may be expected by the asker to transfer the situation from the other question to his case? (+1)
    – Marco13
    Commented Aug 31, 2014 at 0:27

2 Answers 2

17

Not every NullPointerException question is closed as a duplicate of the canonical question, because it's not always clear why a NullPointerException is being raised. Naturally, it occurs when a null object is dereferenced, but sometimes it happens deep in a library, or in a way that is not obvious to the asker.

The kinds of questions I close as duplicates are those where it is apparent that the exception is being raised somewhere in the author's own code, and routine troubleshooting is likely to find the problem. In some cases, where the asker has actually told us which line of code is throwing the exception, it becomes obvious where the null reference is occurring, or that it is occurring in some tertiary object that will be exposed through routine troubleshooting.

I also close such questions as a dupe when it is clear that the author has done no troubleshooting of their own.

6

Every question about NullPointerException is not a duplicate of that one. Just the ones that…

  1. Ask what a NullPointerException is.
  2. Ask how to debug and/or fix a NullPointerException.
  3. Dump a bunch of code that raises a NullPointerException.

These questions are all answered by the title of the canonical duplicate: What is a Null Pointer Exception, and how do I fix it?

It would probably be inappropriate to close other questions related to NullPointerException as a duplicate of that question—though you'd have to make the judgment on a case-by-case basis.

But even if it weren't, the tag isn't hurting anything.

2
  • What other types of questions (besides theoretical ones) would be about NullPointerExceptions but not be duplicates? That's more of what I'm trying to get at.
    – Akshay
    Commented Aug 31, 2014 at 0:17
  • I think a problem with nullpointers is that a dev might know perfectly well what they are, where one occurs, but just doesn't know why a reference is null. The question then is how it came to be. That's sometimes not obvious; an issue with dependency injection, auto-unboxing of wrapper types, concurrent access that sets something to null while local code seems fine... The issue is then really what caused something to become null, but lots of questions mention NPEs get closed as a duplicate even though it would be completely non-obvious to the asker.
    – G_H
    Commented May 19, 2017 at 6:22

Not the answer you're looking for? Browse other questions tagged .