diff --git a/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java b/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java index e91883496..12e3bad62 100644 --- a/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java +++ b/src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java @@ -14,6 +14,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.io.InputStream; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; @@ -99,15 +100,17 @@ public VTimeZone loadVTimeZone(String id) throws IOException, ParserException, P if (!cache.containsId(id)) { final URL resource = ResourceLoader.getResource(resourcePrefix + id + ".ics"); if (resource != null) { - final CalendarBuilder builder = new CalendarBuilder(); - final Calendar calendar = builder.build(resource.openStream()); - final VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE); - // load any available updates for the timezone.. can be explicility disabled via configuration - if (!"false".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("true"))) { - return updateDefinition(vTimeZone); - } - if (vTimeZone != null) { - cache.putIfAbsent(id, vTimeZone); + try (InputStream in = resource.openStream()) { + final CalendarBuilder builder = new CalendarBuilder(); + final Calendar calendar = builder.build(in); + final VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE); + // load any available updates for the timezone.. can be explicility disabled via configuration + if (!"false".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("true"))) { + return updateDefinition(vTimeZone); + } + if (vTimeZone != null) { + cache.putIfAbsent(id, vTimeZone); + } } } else { return generateTimezoneForId(id); diff --git a/src/main/java/net/fortuna/ical4j/util/Configurator.java b/src/main/java/net/fortuna/ical4j/util/Configurator.java index 77f882953..0d6815876 100644 --- a/src/main/java/net/fortuna/ical4j/util/Configurator.java +++ b/src/main/java/net/fortuna/ical4j/util/Configurator.java @@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; +import java.io.InputStream; import java.util.Optional; import java.util.Properties; @@ -55,8 +56,8 @@ public final class Configurator { private static final Properties CONFIG = new Properties(); static { - try { - CONFIG.load(ResourceLoader.getResourceAsStream("ical4j.properties")); + try (InputStream in = ResourceLoader.getResourceAsStream("ical4j.properties")) { + CONFIG.load(in); } catch (IOException | NullPointerException e) { LOG.info("ical4j.properties not found."); }