You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Paul King <pa...@gmail.com> on 2018/08/12 13:54:43 UTC
Re: groovy git commit: Close zip file and input stream
Nice catch. Perhaps just closing the zipfile is enough:
https://bugs.java.com/view_bug.do?bug_id=6735255
But I see now harm in closing the inputstreams though it'd be nice if we
provided a withInputStream DGM method for ZipFile or at least factored
out the dup.
On Sun, Aug 12, 2018 at 10:38 PM <su...@apache.org> wrote:
>
> Repository: groovy
> Updated Branches:
> refs/heads/GROOVY_2_5_X 285755808 -> 61de0a358
>
>
> Close zip 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/61de0a35
> Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/61de0a35
> Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/61de0a35
>
> Branch: refs/heads/GROOVY_2_5_X
> Commit: 61de0a3582524c9967f8c37028f62b8d973d9133
> Parents: 2857558
> Author: Daniel Sun <su...@apache.org>
> Authored: Sun Aug 12 20:38:11 2018 +0800
> Committer: Daniel Sun <su...@apache.org>
> Committed: Sun Aug 12 20:38:11 2018 +0800
>
> ----------------------------------------------------------------------
> src/main/groovy/groovy/grape/GrapeIvy.groovy | 42 +++++++++++++++++++++--
> 1 file changed, 39 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/groovy/blob/61de0a35/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 788cf2e..3912e54 100644
> --- a/src/main/groovy/groovy/grape/GrapeIvy.groovy
> +++ b/src/main/groovy/groovy/grape/GrapeIvy.groovy
> @@ -384,20 +384,48 @@ class GrapeIvy implements GrapeEngine {
> @CompileStatic
> private Collection<String> processMetaInfServices(ClassLoader loader, File f) {
> List<String> services = new ArrayList<>()
> + ZipFile zf = null
> try {
> - ZipFile zf = new ZipFile(f)
> + zf = new ZipFile(f)
> String providerConfig = 'org.codehaus.groovy.runtime.SerializedCategoryMethods'
> ZipEntry serializedCategoryMethods = zf.getEntry(METAINF_PREFIX + providerConfig)
> if (serializedCategoryMethods != null) {
> services.add(providerConfig)
> - processSerializedCategoryMethods(zf.getInputStream(serializedCategoryMethods))
> +
> + InputStream is = null
> + try {
> + is = zf.getInputStream(serializedCategoryMethods)
> + processSerializedCategoryMethods(is)
> + } finally {
> + if (null != is) {
> + try {
> + is.close()
> + } catch (e) {
> + // ignore
> + }
> + }
> + }
> +
> }
> // TODO: remove in a future release (replaced by GroovyRunnerRegistry)
> providerConfig = 'org.codehaus.groovy.plugins.Runners'
> ZipEntry pluginRunners = zf.getEntry(METAINF_PREFIX + providerConfig)
> if (pluginRunners != null) {
> services.add(providerConfig)
> - processRunners(zf.getInputStream(pluginRunners), f.getName(), loader)
> +
> + InputStream is = null
> + try {
> + is = zf.getInputStream(pluginRunners)
> + processRunners(is, f.getName(), loader)
> + } finally {
> + if (null != is) {
> + try {
> + is.close()
> + } catch (e) {
> + // ignore
> + }
> + }
> + }
> }
> // GroovyRunners are loaded per ClassLoader using a ServiceLoader so here
> // it only needs to be indicated that the service provider file was found
> @@ -407,6 +435,14 @@ class GrapeIvy implements GrapeEngine {
> } catch(ZipException ignore) {
> // ignore files we can't process, e.g. non-jar/zip artifacts
> // TODO log a warning
> + } finally {
> + if (null != zf) {
> + try {
> + zf.close()
> + } catch (e) {
> + // ignore
> + }
> + }
> }
> return services
> }
>
Re: groovy git commit: Close zip file and input stream
Posted by "Daniel.Sun" <su...@apache.org>.
Hi Paul,
My solution for handling ZipFile/JarFile is a bit outdated, but it
takes effect ;-)
Cheers,
Daniel.Sun
-----
Daniel Sun
Apache Groovy committer
Blog: http://blog.sunlan.me
Twitter: @daniel_sun
--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html