DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

NullPointerException in EnumMultiset.create #1723

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The attached two tests on two variants of create cause a NullPointerException. 
I am not sure if this is a bug, because some collections do not allow null 
values; however, I could not find anything in the documentation about these 
exact cases.

Original issue reported on code.google.com by cyrille....@gmail.com on 11 Apr 2014 at 3:59

Attachments:

GoogleCodeExporter commented 9 years ago
Is there any way to reproduce this without the raw types?

Original comment by wasserman.louis on 11 Apr 2014 at 4:06

GoogleCodeExporter commented 9 years ago
This test was first auto-generated and then manually reduced by us. I am afraid 
I am not sure how to simplify it further.

Original comment by cyrille....@gmail.com on 11 Apr 2014 at 4:28

GoogleCodeExporter commented 9 years ago
Have you looked at the stack traces of these NPEs? In both cases, the NPE 
happens because you're passing a Class that is _not_ an enum class to a method 
that requires a Class<E extends Enum<E>>. It isn't possible to do that without 
using raw types, and if you're using raw types any guarantees of safety go 
right out the window.

Original comment by cgdecker@google.com on 11 Apr 2014 at 3:37

GoogleCodeExporter commented 9 years ago
I see. How about inserting a type check in a few places such that the exception 
is IllegalArgumentException or ClassCastException? That would be clearer to the 
user, as no null pointer is used to produce the bug. (Of course each type check 
adds some overhead; I'll leave it up to you to prioritize performance vs. ease 
of use here.)

Original comment by cyrille....@gmail.com on 13 Apr 2014 at 11:49

GoogleCodeExporter commented 9 years ago
I don't think it's worth making code changes to prevent against problems that 
are already prevented by simply obeying the compiler warnings you're already 
getting.

Original comment by kevinb@google.com on 14 Apr 2014 at 1:48

GoogleCodeExporter commented 9 years ago
OK, then we count this test as a false warning.

Original comment by cyrille....@gmail.com on 14 Apr 2014 at 2:20

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:09

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07