Fix: Resources should be closed

Java 7 introduced the try-with-resources statement,
which implicitly closes Closeables.

Fixes sonar rule squid:S2095
This commit is contained in:
Sebastian Peters
2018-11-19 22:13:06 +01:00
parent ef361b1bd0
commit 176a0d7752
8 changed files with 45 additions and 49 deletions
@@ -104,14 +104,17 @@ public class StrutsSpringObjectFactory extends SpringObjectFactory {
//prevent class caching
useClassCache = false;
ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext) appContext;
reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext, "true".equals(reloadConfig));
LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!\n{}", watchList);
try (ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext) appContext) {
reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext,
"true".equals(reloadConfig));
LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!\n{}",
watchList);
setClassLoader(reloadingContext.getReloadingClassLoader());
setClassLoader(reloadingContext.getReloadingClassLoader());
//we need to reload the context, so our isntance of the factory is picked up
reloadingContext.refresh();
// we need to reload the context, so our isntance of the factory is picked up
reloadingContext.refresh();
}
}
this.setApplicationContext(appContext);