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
Original issue reported on code.google.com by
mala...@gmail.com
on 18 Sep 2009 at 11:02Attachments: