From 854fb82fdba45c4034c1dac049b4174d6523f2ee Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 9 Apr 2015 14:42:57 +0300 Subject: [PATCH] close stream --- .../plugins/intelliLang/Configuration.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java index 8db552b12ee6..ea2f54627a8e 100644 --- a/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java +++ b/plugins/IntelliLang/src/org/intellij/plugins/intelliLang/Configuration.java @@ -206,14 +206,14 @@ public class Configuration extends SimpleModificationTracker implements Persiste }; protected Collection getAllInjections() { - ArrayList injections = new ArrayList(); + List injections = new ArrayList(); for (List list : myInjections.values()) { injections.addAll(list); } return injections; } - private CachedValue> myInjectionsById = new CachedValueImpl>(new CachedValueProvider>() { + private final CachedValue> myInjectionsById = new CachedValueImpl>(new CachedValueProvider>() { @Nullable @Override public Result> compute() { @@ -235,7 +235,7 @@ public class Configuration extends SimpleModificationTracker implements Persiste @Override public void loadState(final Element element) { myInjections.clear(); - final THashMap supports = new THashMap(); + final Map supports = new THashMap(); for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { supports.put(support.getId(), support); } @@ -271,8 +271,8 @@ public class Configuration extends SimpleModificationTracker implements Persiste } private static List loadDefaultInjections() { - final ArrayList cfgList = new ArrayList(); - final THashSet visited = new THashSet(); + final List cfgList = new ArrayList(); + final Set visited = new THashSet(); for (LanguageInjectionConfigBean configBean : Extensions.getExtensions(LanguageInjectionSupport.CONFIG_EP_NAME)) { PluginDescriptor descriptor = configBean.getPluginDescriptor(); final ClassLoader loader = descriptor.getPluginClassLoader(); @@ -285,12 +285,19 @@ public class Configuration extends SimpleModificationTracker implements Persiste while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); if (!visited.add(url.getFile())) continue; // for DEBUG mode + InputStream stream = null; try { - cfgList.add(load(url.openStream())); + stream = url.openStream(); + cfgList.add(load(stream)); } catch (Exception e) { LOG.warn(e); } + finally { + if (stream != null) { + stream.close(); + } + } } } } @@ -299,7 +306,7 @@ public class Configuration extends SimpleModificationTracker implements Persiste } } - final ArrayList defaultInjections = new ArrayList(); + final List defaultInjections = new ArrayList(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { for (Configuration cfg : cfgList) { final List imported = cfg.getInjections(supportId); @@ -324,7 +331,7 @@ public class Configuration extends SimpleModificationTracker implements Persiste List injectorIds = new ArrayList(myInjections.keySet()); Collections.sort(injectorIds); for (String key : injectorIds) { - TreeSet injections = new TreeSet(comparator); + Set injections = new TreeSet(comparator); injections.addAll(myInjections.get(key)); injections.removeAll(getDefaultInjections()); for (BaseInjection injection : injections) { @@ -352,7 +359,7 @@ public class Configuration extends SimpleModificationTracker implements Persiste @Nullable public static Configuration load(final InputStream is) throws IOException, JDOMException { - final ArrayList elements = new ArrayList(); + final List elements = new ArrayList(); final Element rootElement = JDOMUtil.load(is); final Element state; if (rootElement.getName().equals(COMPONENT_NAME)) { @@ -384,8 +391,8 @@ public class Configuration extends SimpleModificationTracker implements Persiste return o.getSupportId(); } }); - final ArrayList originalInjections = new ArrayList(); - final ArrayList newInjections = new ArrayList(); + List originalInjections = new ArrayList(); + List newInjections = new ArrayList(); for (String supportId : InjectorUtils.getActiveInjectionSupportIds()) { final Set importingInjections = map.get(supportId); if (importingInjections == null) continue; @@ -448,8 +455,8 @@ public class Configuration extends SimpleModificationTracker implements Persiste } public boolean setHostInjectionEnabled(final PsiLanguageInjectionHost host, final Collection languages, final boolean enabled) { - final ArrayList originalInjections = new ArrayList(); - final ArrayList newInjections = new ArrayList(); + List originalInjections = new ArrayList(); + List newInjections = new ArrayList(); for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) { for (BaseInjection injection : getInjections(support.getId())) { if (!languages.contains(injection.getInjectedLanguageId())) continue;