Skip to content

Commit 90512f0

Browse files
committed
Fixed SPR issue reference and aligned exception messages
Issue: SPR-11592
1 parent 9fc13e1 commit 90512f0

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public CacheManager getCacheManager() {
103103
* @param cacheOperationSources must not be {@code null}
104104
*/
105105
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
106-
Assert.notEmpty(cacheOperationSources);
106+
Assert.notEmpty(cacheOperationSources, "At least 1 CacheOperationSource needs to be specified");
107107
this.cacheOperationSource = (cacheOperationSources.length > 1 ?
108108
new CompositeCacheOperationSource(cacheOperationSources) : cacheOperationSources[0]);
109109
}
@@ -131,8 +131,8 @@ public KeyGenerator getKeyGenerator() {
131131
}
132132

133133
public void afterPropertiesSet() {
134-
Assert.state(this.cacheManager != null, "'cacheManager' is required");
135-
Assert.state(this.cacheOperationSource != null, "The 'cacheOperationSources' property is required: " +
134+
Assert.state(this.cacheManager != null, "Property 'cacheManager' is required");
135+
Assert.state(this.cacheOperationSource != null, "Property 'cacheOperationSources' is required: " +
136136
"If there are no cacheable methods, then don't use a cache aspect.");
137137
this.initialized = true;
138138
}
@@ -157,7 +157,9 @@ protected Collection<? extends Cache> getCaches(CacheOperation operation) {
157157
Collection<Cache> caches = new ArrayList<Cache>(cacheNames.size());
158158
for (String cacheName : cacheNames) {
159159
Cache cache = this.cacheManager.getCache(cacheName);
160-
Assert.notNull(cache, "Cannot find cache named '" + cacheName + "' for " + operation);
160+
if (cache == null) {
161+
throw new IllegalArgumentException("Cannot find cache named '" + cacheName + "' for " + operation);
162+
}
161163
caches.add(cache);
162164
}
163165
return caches;

spring-context/src/test/java/org/springframework/cache/CacheReproTests.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public void spr11249() throws Exception {
6666
}
6767

6868
@Test
69-
public void spr11595GetSimple() {
70-
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11595Config.class);
71-
Spr11595Service bean = context.getBean(Spr11595Service.class);
69+
public void spr11592GetSimple() {
70+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
71+
Spr11592Service bean = context.getBean(Spr11592Service.class);
7272
Cache cache = context.getBean("cache", Cache.class);
7373

7474
String key = "1";
@@ -83,9 +83,9 @@ public void spr11595GetSimple() {
8383
}
8484

8585
@Test
86-
public void spr11595GetNeverCache(){
87-
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11595Config.class);
88-
Spr11595Service bean = context.getBean(Spr11595Service.class);
86+
public void spr11592GetNeverCache(){
87+
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11592Config.class);
88+
Spr11592Service bean = context.getBean(Spr11592Service.class);
8989
Cache cache = context.getBean("cache", Cache.class);
9090

9191
String key = "1";
@@ -179,7 +179,7 @@ public Object doSomething(String name, int... values) {
179179

180180
@Configuration
181181
@EnableCaching
182-
public static class Spr11595Config {
182+
public static class Spr11592Config {
183183

184184
@Bean
185185
public CacheManager cacheManager() {
@@ -195,14 +195,13 @@ public Cache cache() {
195195
}
196196

197197
@Bean
198-
public Spr11595Service service() {
199-
return new Spr11595Service();
198+
public Spr11592Service service() {
199+
return new Spr11592Service();
200200
}
201-
202201
}
203202

204203

205-
public static class Spr11595Service {
204+
public static class Spr11592Service {
206205

207206
@Cacheable("cache")
208207
public Object getSimple(String key) {

0 commit comments

Comments
 (0)