Skip to content

Commit 2de6495

Browse files
klueverGoogle Java Core Libraries
authored andcommitted
Add a test ahead of fixing #5438, #7625, and #7975.
PiperOrigin-RevId: 805905405
1 parent 2de2021 commit 2de6495

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

guava-tests/test/com/google/common/cache/LocalCacheMapComputeTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ public void onRemoval(RemovalNotification<Integer, Integer> notification) {
125125
CacheTesting.checkEmpty(cache);
126126
}
127127

128+
public void testComputeIfPresent_error() {
129+
Cache<String, String> cache = CacheBuilder.newBuilder().build();
130+
cache.put(key, "1");
131+
assertThrows(
132+
Error.class,
133+
() ->
134+
cache
135+
.asMap()
136+
.computeIfPresent(
137+
key,
138+
(k, v) -> {
139+
throw new Error();
140+
}));
141+
assertThat(cache.getIfPresent(key)).isEqualTo("1");
142+
assertThat(cache.asMap().computeIfPresent(key, (k, v) -> "2")).isEqualTo(null);
143+
}
144+
128145
public void testUpdates() {
129146
cache.put(key, "1");
130147
// simultaneous update for same key, some null, some non-null

0 commit comments

Comments
 (0)