fix NPE in putAll
This commit is contained in:
parent
0483aa0bba
commit
9a15022520
4 changed files with 15 additions and 1 deletions
|
@ -45,6 +45,9 @@ public abstract class IndexedCollectionBase<T> extends AbstractCollection<T> imp
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEach(Consumer<? super T> action) {
|
public void forEach(Consumer<? super T> action) {
|
||||||
|
if (action == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int i = 0; i < rawSize(); i++) {
|
for (int i = 0; i < rawSize(); i++) {
|
||||||
if (!isRemoved(i)) {
|
if (!isRemoved(i)) {
|
||||||
action.accept(getEntryAt(i));
|
action.accept(getEntryAt(i));
|
||||||
|
|
|
@ -112,6 +112,9 @@ public abstract class IndexedMapBase<K, V> implements IndexedMap<K, V> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putAll(Map<? extends K, ? extends V> m) {
|
public void putAll(Map<? extends K, ? extends V> m) {
|
||||||
|
if (m == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
m.forEach(this::put);
|
m.forEach(this::put);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,14 @@ public class TinyMapTest {
|
||||||
assertEquals(100, set.size());
|
assertEquals(100, set.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPutAllNull() {
|
||||||
|
TinyMap.Builder<String, Object> builder = TinyMap.builder();
|
||||||
|
builder.put("a", "b");
|
||||||
|
builder.putAll(null);
|
||||||
|
assertEquals(1, builder.build().size());
|
||||||
|
}
|
||||||
|
|
||||||
private void testCount(int count, boolean withNull) {
|
private void testCount(int count, boolean withNull) {
|
||||||
TinyMap.Builder<String, Object> builder = TinyMap.builder();
|
TinyMap.Builder<String, Object> builder = TinyMap.builder();
|
||||||
LinkedHashMap<String, Object> expectedMap = new LinkedHashMap<>();
|
LinkedHashMap<String, Object> expectedMap = new LinkedHashMap<>();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = datastructures
|
name = datastructures
|
||||||
version = 0.0.2
|
version = 0.0.3
|
||||||
|
|
||||||
gradle.wrapper.version = 6.6.1
|
gradle.wrapper.version = 6.6.1
|
||||||
|
|
Loading…
Reference in a new issue