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:15:39 UTC
[2/2] groovy git commit: Close jar file and input stream
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/28575580
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/28575580
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/28575580
Branch: refs/heads/GROOVY_2_5_X
Commit: 28575580843161b3eb46ca21fb5b53ec58f7753a
Parents: 1c0aaa6
Author: Daniel Sun <su...@apache.org>
Authored: Sun Aug 12 20:15:18 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Sun Aug 12 20:15:18 2018 +0800
----------------------------------------------------------------------
src/main/groovy/groovy/grape/GrapeIvy.groovy | 29 +++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/28575580/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..788cf2e 100644
--- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
+++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
@@ -315,15 +315,29 @@ class GrapeIvy implements GrapeEngine {
if (file.name.toLowerCase().endsWith(".jar")) {
def mcRegistry = GroovySystem.metaClassRegistry
if (mcRegistry instanceof MetaClassRegistryImpl) {
+ JarFile jar = null
try {
- JarFile jar = new JarFile(file)
+ 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))
+ InputStream is = null
+ try {
+ is = jar.getInputStream(entry)
+ props.load(is)
+ } finally {
+ if (null != is) {
+ try {
+ is.close()
+ } catch (e) {
+ // ignore
+ }
+ }
+ }
+
Map<CachedClass, List<MetaMethod>> metaMethods = new HashMap<CachedClass, List<MetaMethod>>()
mcRegistry.registerExtensionModuleFromProperties(props, loader, metaMethods)
// add old methods to the map
@@ -339,9 +353,16 @@ class GrapeIvy implements GrapeEngine {
classesToBeUpdated*.addNewMopMethods(methods)
}
}
- }
- catch(ZipException zipException) {
+ } catch(ZipException zipException) {
throw new RuntimeException("Grape could not load jar '$file'", zipException)
+ } finally {
+ if (null != jar) {
+ try {
+ jar.close()
+ } catch (e) {
+ // ignore
+ }
+ }
}
}
}