BAEL-6600: fix flaws in the logic of put method

This commit is contained in:
mcasari 2023-11-14 23:22:44 +01:00
parent 2f9407e765
commit 8a31837a3e
1 changed files with 5 additions and 8 deletions

View File

@ -15,13 +15,10 @@ public class HashMapWithMaxSizeLimit<K, V> extends HashMap<K, V> {
@Override
public V put(K key, V value) {
V res = null;
if (this.maxSize == -1 || this.size() < this.maxSize) {
res = super.put(key, value);
} else if (this.maxSize != -1) {
throw new RuntimeException("Max size exceeded!");
if (this.maxSize == -1 || this.containsKey(key) || this.size() < this.maxSize) {
return super.put(key, value);
}
return res;
throw new RuntimeException("Max size exceeded!");
}
}