You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/08/12 12:06:28 UTC

groovy git commit: Close jar file and input stream

Repository: groovy
Updated Branches:
  refs/heads/master 87934f43d -> 7ca01a6ad


Close jar file and input stream


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7ca01a6a
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7ca01a6a
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7ca01a6a

Branch: refs/heads/master
Commit: 7ca01a6ad4e8cb325a30d0a8742dd04ff98720fb
Parents: 87934f4
Author: Daniel Sun <su...@apache.org>
Authored: Sun Aug 12 20:05:05 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Aug 12 20:05:05 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/grape/GrapeIvy.groovy | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/7ca01a6a/src/main/groovy/groovy/grape/GrapeIvy.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/grape/GrapeIvy.groovy b/src/main/groovy/groovy/grape/GrapeIvy.groovy
index bc8b3f7..2ac4a83 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -315,15 +315,18 @@ class GrapeIvy implements GrapeEngine {
         if (file.name.toLowerCase().endsWith(".jar")) {
             def mcRegistry = GroovySystem.metaClassRegistry
             if (mcRegistry instanceof MetaClassRegistryImpl) {
-                try {
-                    JarFile jar = new JarFile(file)
+                try (JarFile jar = new JarFile(file)) {
                     def entry = jar.getEntry(ExtensionModuleScanner.MODULE_META_INF_FILE)
                     if (!entry) {
                         entry = jar.getEntry(ExtensionModuleScanner.LEGACY_MODULE_META_INF_FILE)
                     }
                     if (entry) {
                         Properties props = new Properties()
-                        props.load(jar.getInputStream(entry))
+
+                        try (InputStream is = jar.getInputStream(entry)) {
+                            props.load(is)
+                        }
+
                         Map<CachedClass, List<MetaMethod>> metaMethods = new HashMap<CachedClass, List<MetaMethod>>()
                         mcRegistry.registerExtensionModuleFromProperties(props, loader, metaMethods)
                         // add old methods to the map
@@ -339,8 +342,7 @@ class GrapeIvy implements GrapeEngine {
                             classesToBeUpdated*.addNewMopMethods(methods)
                         }
                     }
-                }
-                catch(ZipException zipException) {
+                } catch(ZipException zipException) {
                     throw new RuntimeException("Grape could not load jar '$file'", zipException)
                 }
             }