diff --git a/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java b/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java index bd47592f8f..232c41bc07 100644 --- a/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java +++ b/src/main/java/org/apache/commons/collections4/map/ConcurrentReferenceHashMap.java @@ -1303,9 +1303,7 @@ private WriteThroughEntry(final K k, final V v) { */ @Override public V setValue(final V value) { - if (value == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(value, "value"); final V v = super.setValue(value); ConcurrentReferenceHashMap.this.put(getKey(), value); return v; @@ -1553,9 +1551,7 @@ public boolean containsKey(final Object key) { */ @Override public boolean containsValue(final Object value) { - if (value == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(value, "value"); // See explanation of modCount use above final Segment[] segments = this.segments; final int[] mc = new int[segments.length]; @@ -1715,9 +1711,8 @@ public void purgeStaleEntries() { */ @Override public V put(final K key, final V value) { - if (key == null || value == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(key, "key"); + Objects.requireNonNull(value, "value"); final int hash = hashOf(key); return segmentFor(hash).put(key, hash, value, null, false); } @@ -1743,9 +1738,7 @@ public void putAll(final Map m) { */ @Override public V putIfAbsent(final K key, final V value) { - if (value == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(value, "value"); final int hash = hashOf(key); return segmentFor(hash).put(key, hash, value, null, true); } @@ -1785,9 +1778,7 @@ public boolean remove(final Object key, final Object value) { */ @Override public V replace(final K key, final V value) { - if (value == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(value, "value"); final int hash = hashOf(key); return segmentFor(hash).replace(key, hash, value); } @@ -1799,9 +1790,8 @@ public V replace(final K key, final V value) { */ @Override public boolean replace(final K key, final V oldValue, final V newValue) { - if (oldValue == null || newValue == null) { - throw new NullPointerException(); - } + Objects.requireNonNull(oldValue, "oldValue"); + Objects.requireNonNull(newValue, "newValue"); final int hash = hashOf(key); return segmentFor(hash).replace(key, hash, oldValue, newValue); }