From de932903ca3922d9cdcb87c3a81ee23aa266ea54 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 10 Oct 2015 22:43:06 +0200 Subject: [PATCH] Reliable null value handling in ConcurrentMapCache, GuavaCache, JCacheCache The 4.1 variant of this fix just introduces readResolve declarations to the existing NullHolder classes. Issue: SPR-13553 --- .../java/org/springframework/cache/guava/GuavaCache.java | 8 ++++++-- .../org/springframework/cache/jcache/JCacheCache.java | 6 +++++- .../cache/concurrent/ConcurrentMapCache.java | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java index 7e8b71429e8..1f3d46e01bd 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/guava/GuavaCache.java @@ -28,8 +28,8 @@ import org.springframework.cache.support.SimpleValueWrapper; import org.springframework.util.Assert; /** - * Spring {@link Cache} adapter implementation on top of a - * Guava {@link com.google.common.cache.Cache} instance. + * Spring {@link org.springframework.cache.Cache} adapter implementation + * on top of a Guava {@link com.google.common.cache.Cache} instance. * *

Requires Google Guava 12.0 or higher. * @@ -174,6 +174,10 @@ public class GuavaCache implements Cache { @SuppressWarnings("serial") private static class NullHolder implements Serializable { + + private Object readResolve() { + return NULL_HOLDER; + } } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java index 372e754c9fa..ee39da7a90c 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,6 +142,10 @@ public class JCacheCache implements Cache { @SuppressWarnings("serial") private static class NullHolder implements Serializable { + + private Object readResolve() { + return NULL_HOLDER; + } } } diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java index bb3a472e15f..cd6029fdc25 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCache.java @@ -25,8 +25,8 @@ import org.springframework.cache.support.SimpleValueWrapper; import org.springframework.util.Assert; /** - * Simple {@link Cache} implementation based on the core JDK - * {@code java.util.concurrent} package. + * Simple {@link org.springframework.cache.Cache} implementation based on the + * core JDK {@code java.util.concurrent} package. * *

Useful for testing or simple caching scenarios, typically in combination * with {@link org.springframework.cache.support.SimpleCacheManager} or @@ -172,6 +172,10 @@ public class ConcurrentMapCache implements Cache { @SuppressWarnings("serial") private static class NullHolder implements Serializable { + + private Object readResolve() { + return NULL_HOLDER; + } } }