Skip to content

Commit 67d9b8b

Browse files
committed
EhCacheManagerFactoryBean properly closes "ehcache.xml" input stream, if any (SPR-7813)
1 parent cc91efe commit 67d9b8b

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

org.springframework.context.support/src/main/java/org/springframework/cache/ehcache/EhCacheManagerFactoryBean.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.cache.ehcache;
1818

1919
import java.io.IOException;
20+
import java.io.InputStream;
2021

2122
import net.sf.ehcache.CacheException;
2223
import net.sf.ehcache.CacheManager;
@@ -97,23 +98,17 @@ public void setCacheManagerName(String cacheManagerName) {
9798

9899
public void afterPropertiesSet() throws IOException, CacheException {
99100
logger.info("Initializing EHCache CacheManager");
100-
if (this.shared) {
101-
// Shared CacheManager singleton at the VM level.
102-
if (this.configLocation != null) {
103-
this.cacheManager = CacheManager.create(this.configLocation.getInputStream());
101+
if (this.configLocation != null) {
102+
InputStream is = this.configLocation.getInputStream();
103+
try {
104+
this.cacheManager = (this.shared ? CacheManager.create(is) : new CacheManager(is));
104105
}
105-
else {
106-
this.cacheManager = CacheManager.create();
106+
finally {
107+
is.close();
107108
}
108109
}
109110
else {
110-
// Independent CacheManager instance (the default).
111-
if (this.configLocation != null) {
112-
this.cacheManager = new CacheManager(this.configLocation.getInputStream());
113-
}
114-
else {
115-
this.cacheManager = new CacheManager();
116-
}
111+
this.cacheManager = (this.shared ? CacheManager.create() : new CacheManager());
117112
}
118113
if (this.cacheManagerName != null) {
119114
this.cacheManager.setName(this.cacheManagerName);

0 commit comments

Comments
 (0)