Detect custom deserialized NullValue instances

Closes gh-36727

(cherry picked from commit 916cb64581)
This commit is contained in:
Juergen Hoeller
2026-04-29 22:02:13 +02:00
parent a58fdeaf3f
commit 8b5cbb7496
2 changed files with 9 additions and 1 deletions
@@ -87,7 +87,7 @@ public abstract class AbstractValueAdaptingCache implements Cache {
*/
@Nullable
protected Object fromStoreValue(@Nullable Object storeValue) {
if (this.allowNullValues && storeValue == NullValue.INSTANCE) {
if (this.allowNullValues && storeValue instanceof NullValue) {
return null;
}
return storeValue;
@@ -24,7 +24,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.Cache;
import org.springframework.cache.support.NullValue;
import static org.assertj.core.api.Assertions.assertThat;
@@ -72,6 +74,12 @@ public abstract class AbstractCacheTests<T extends Cache> {
assertThat(cache.get(key).get()).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
cache.put(key, BeanUtils.instantiateClass(NullValue.class));
assertThat(cache.get(key)).isNotNull();
assertThat(cache.get(key).get()).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
}
@Test