Version of Cache2k:2.0.0.Final
How to reproduce:
- Run the following two unit test cases.
testNpeWithoutListener passes but testNpeWithListener fails
package org.cache2k.test;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.concurrent.TimeUnit;
import org.cache2k.Cache;
import org.cache2k.Cache2kBuilder;
import org.cache2k.event.CacheEntryRemovedListener;
import org.hamcrest.Matchers;
import org.junit.Test;
public class TestCache2k {
@Test
public void testNpeWithoutListener() {
testAndVerifyStacktrace(Cache2kBuilder.of(String.class, String.class)
.expireAfterWrite(10, TimeUnit.SECONDS)
.entryCapacity(10)
// no listener added
.build());
}
@Test
public void testNpeWithListener() {
testAndVerifyStacktrace(Cache2kBuilder.of(String.class, String.class)
.expireAfterWrite(10, TimeUnit.SECONDS)
.entryCapacity(10)
// listener added
.addListener((CacheEntryRemovedListener<String, String>) (cache1, cacheEntry) -> {
})
.build());
}
private static void testAndVerifyStacktrace(Cache<String, String> cache) {
try {
final String value = null;
cache.computeIfAbsent("npeKey", s -> value.substring(10));
fail("this shall not pass");
} catch (NullPointerException e) {
assertThat(e.getStackTrace()[0].getClassName(), Matchers.is(TestCache2k.class.getName()));
}
}
}
Expectations: Both two cases pass, i.e. stacktrace within the callback function of computeIfAbsent should not be replaced by cache
Possible Reason: Stacktrace of the Exception thrown by the client callback function is replaced here
Version of Cache2k:2.0.0.Final
How to reproduce:
testNpeWithoutListenerpasses buttestNpeWithListenerfailsExpectations: Both two cases pass, i.e. stacktrace within the callback function of
computeIfAbsentshould not be replaced by cachePossible Reason: Stacktrace of the
Exceptionthrown by the client callback function is replaced herecache2k/cache2k-core/src/main/java/org/cache2k/core/BaseCache.java
Line 225 in 8a0024c