Skip to content

Commit

Permalink
IDEMPIERE-6079 fix NPE caused by library ben-manes/caffeine (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRuiz-globalqss committed Apr 26, 2024
1 parent 9706972 commit d707ffd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions org.adempiere.base/src/org/compiere/util/CCache.java
Expand Up @@ -369,6 +369,8 @@ public void clear()
@Override
public boolean containsKey(Object key)
{
if (key == null)
return false;
return cache.containsKey(key) || nullList.contains(key);
} // containsKey

Expand All @@ -378,6 +380,8 @@ public boolean containsKey(Object key)
@Override
public boolean containsValue(Object value)
{
if (value == null)
return false;
return cache.containsValue(value);
} // containsValue

Expand All @@ -397,6 +401,8 @@ public Set<Map.Entry<K,V>> entrySet()
@Override
public V get(Object key)
{
if (key == null)
return null;
V v = cache.get(key);
if (v == null)
if (nullList.contains(key))
Expand Down
Expand Up @@ -24,6 +24,7 @@
**********************************************************************/
package org.idempiere.test.performance;

import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -946,4 +947,16 @@ public void testExpire() {

CacheMgt.get().unregister(cache);
}

@Test
public void testNullKey() {
CCache<String, String> testCache = new CCache<String, String>(null, "Test_Cache", 10, 60, false);
assertThatNoException().isThrownBy(() -> testCache.get(null));
assertThatNoException().isThrownBy(() -> testCache.containsKey(null));
assertThatNoException().isThrownBy(() -> testCache.containsValue(null));
assertFalse(testCache.containsValue(null));
testCache.put("TestNull", null);
assertFalse(testCache.containsValue(null)); // still false because null is an unknown value
}

}

0 comments on commit d707ffd

Please sign in to comment.