1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-22 14:22:05 +01:00

Close stream in UrlInitializer

This commit is contained in:
Florian Schmaus 2018-08-13 16:39:28 +02:00
parent 384e1852cc
commit 5517d03fae

View file

@ -16,6 +16,7 @@
*/ */
package org.jivesoftware.smack.initializer; package org.jivesoftware.smack.initializer;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.LinkedList; import java.util.LinkedList;
@ -39,7 +40,7 @@ public abstract class UrlInitializer implements SmackInitializer {
@Override @Override
public List<Exception> initialize() { public List<Exception> initialize() {
InputStream is; InputStream is = null;
final ClassLoader classLoader = this.getClass().getClassLoader(); final ClassLoader classLoader = this.getClass().getClassLoader();
final List<Exception> exceptions = new LinkedList<Exception>(); final List<Exception> exceptions = new LinkedList<Exception>();
final String providerUriString = getProvidersUri(); final String providerUriString = getProvidersUri();
@ -56,6 +57,8 @@ public abstract class UrlInitializer implements SmackInitializer {
catch (Exception e) { catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUriString, e); LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUriString, e);
exceptions.add(e); exceptions.add(e);
} finally {
maybeClose(is);
} }
} }
final String configUriString = getConfigUri(); final String configUriString = getConfigUri();
@ -67,6 +70,8 @@ public abstract class UrlInitializer implements SmackInitializer {
} }
catch (Exception e) { catch (Exception e) {
exceptions.add(e); exceptions.add(e);
} finally {
maybeClose(is);
} }
} }
return exceptions; return exceptions;
@ -79,4 +84,16 @@ public abstract class UrlInitializer implements SmackInitializer {
protected String getConfigUri() { protected String getConfigUri() {
return null; return null;
} }
private static void maybeClose(InputStream is) {
if (is == null) {
return;
}
try {
is.close();
}
catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not close input stream", e);
}
}
} }