Fixes DB Extension autoclose stream with try with resources
* Fixes autoclose stream with try with resources
uses newer try with resources to autoclose stream regardless
* simplify stream variable assignment
@@ -111,20 +111,18 @@ public class DatabaseModuleImpl extends ButterflyModuleImpl {
if(logger.isDebugEnabled()) {
logger.debug("Loading Extension properties ({})", propFile);
}
- BufferedInputStream stream = null;
- try {
+
+ try (final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(propFile))) {
ps = new Properties();
- stream = new BufferedInputStream(new FileInputStream(propFile));
ps.load(stream);
-
- } finally {
- // Close the stream.
- if (stream != null) stream.close();
}
}
} catch (Exception e) {
logger.error("Error loading Database properties", e);
+ /* During an exception reading 'dbextension.properties' (security or no permissions for example)
+ * the try with resources will autoclose the stream for us. And then we log the exception.
+ */
}
return ps;
}
