diff --git a/src/org/jgroups/JChannel.java b/src/org/jgroups/JChannel.java index 98f0dab5f9..13f0b2ddc7 100644 --- a/src/org/jgroups/JChannel.java +++ b/src/org/jgroups/JChannel.java @@ -107,7 +107,8 @@ public JChannel(String props) throws Exception { /** * Creates a channel with a configuration based on an input stream. - * @param input An input stream, pointing to a streamed configuration + * @param input An input stream, pointing to a streamed configuration. It is the caller's resposibility to close + * the input stream after the constructor returns */ public JChannel(InputStream input) throws Exception { this(ConfiguratorFactory.getStackConfigurator(input)); diff --git a/src/org/jgroups/conf/ConfiguratorFactory.java b/src/org/jgroups/conf/ConfiguratorFactory.java index ab92615af0..140abe4934 100644 --- a/src/org/jgroups/conf/ConfiguratorFactory.java +++ b/src/org/jgroups/conf/ConfiguratorFactory.java @@ -164,15 +164,15 @@ public static InputStream getConfigStream(Object properties) throws IOException */ static XmlConfigurator getXmlConfigurator(String properties) throws IOException { XmlConfigurator returnValue=null; - InputStream configStream=getConfigStream(properties); - if(configStream == null && properties.endsWith("xml")) - throw new FileNotFoundException(String.format(Util.getMessage("FileNotFound"), properties)); + try(InputStream configStream=getConfigStream(properties)) { + if(configStream == null && properties.endsWith("xml")) + throw new FileNotFoundException(String.format(Util.getMessage("FileNotFound"), properties)); - if (configStream != null) { - checkJAXPAvailability(); - returnValue=XmlConfigurator.getInstance(configStream); + if(configStream != null) { + checkJAXPAvailability(); + returnValue=XmlConfigurator.getInstance(configStream); + } } - return returnValue; }