pkt1583 / google-collections

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

NullPointerException in BiMap.put and BiMap.forcePut #246

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In BiMap, put and forcePut have @Nullable annotations.

 V put(@Nullable K key, @Nullable V value);
 V forcePut(@Nullable K key, @Nullable V value);

These annotations indicate that a BiMap should always allow @Nullable
keys and @Nullable values.  In other words, the following methods
should never throw a NullPointerException:

 private void BiMapPut(BiMap<Object, Object> bm) {
  bm.put(null, null); // should never throw a NullPointerException
 }

 private void BiMapForcePut(BiMap<Object, Object> bm) {
  bm.forcePut(null, null); // should never throw a NullPointerException
 }

However, the following unit tests fail by throwing a NullPointerException:

 public void applyTest1() {
  biMapPut(ImmutableBiMap.of());
 }

 public void applyTest2() {
  biMapForcePut(ImmutableBiMap.of());
 }

The Javadoc for ImmutableBiMap, which is a subclass of BiMap,
indicates the following on line 26:

* An immutable {@link BiMap} with reliable user-specified iteration
order. Does not permit null keys or values.

This is incompatible with the specification of BiMap, as expressed by
BiMap's annotations.

Proposed fix:  Remove the @Nullable annotations on line 45 and 64.
Once it is removed, the Multiset annotations correctly reflect the
fact that a client cannot count on null definitely being a legal
element.

A patch for the fix is BiMapFix.patch

Original issue reported on code.google.com by mala...@gmail.com on 18 Sep 2009 at 11:02

Attachments:

GoogleCodeExporter commented 9 years ago
See the @Nullable discussion in issue 247.

Original comment by limpbizkit on 19 Sep 2009 at 6:33

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 19 Sep 2009 at 6:35