-
-
Notifications
You must be signed in to change notification settings - Fork 76
Closed
Description
Version of Cache2k:2.0.0.Final
How to reproduce:
- Run the following two unit test cases.
testNpeWithoutListenerpasses buttestNpeWithListenerfails
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
| t.fillInStackTrace(); |