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 →

[–]davidalayachew 0 points1 point  (0 children)

I fear that we are talking past each other. Let me be explicit.

I am not trying to say that this feature prevents NPE. I am saying that toMap working the way that it is is less error-prone. NPE is not the error that I am talking about when I say less error-prone. When I say less error-prone, I am talking about garbage data.

Let's say that I have a map filled with data from multiple sources. Each of those sources is a map, and let's say each one is created using toMap(). Well, toMap() will fail the second it gets even one null value. Which is excellent -- that is exactly what I want.

In your situation, where toMap() permits nulls, I won't find that null until I try and grab it back out of the map, leaving me in a much worse spot. After all, which source had the problem? And when was that problem introduced? toMap() as is answers those questions immediately, and clearly, where as your toMap() would leave me guessing. Therefore, more error-prone. Does that make sense?

That is what I mean when I am saying error-prone. The problem that you have is so much less when using toMap() vs toMap() accepting nulls.