You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by mushketyk <gi...@git.apache.org> on 2016/06/27 21:35:55 UTC

[GitHub] flink pull request #2172: [FLINK-4096] Ensure JarOutputStream is always clos...

GitHub user mushketyk opened a pull request:

    https://github.com/apache/flink/pull/2172

    [FLINK-4096] Ensure JarOutputStream is always closed

    Thanks for contributing to Apache Flink. Before you open your pull request, please take the following check list into consideration.
    If your changes take all of the items into account, feel free to open your pull request. For more information and/or questions please refer to the [How To Contribute guide](http://flink.apache.org/how-to-contribute.html).
    In addition to going through the list, please provide a meaningful description of your changes.
    
    - [x] General
      - The pull request references the related JIRA issue ("[FLINK-XXX] Jira title text")
      - The pull request addresses only one issue
      - Each commit in the PR has a meaningful commit message (including the JIRA id)
    
    - [x] Documentation
      - Documentation has been added for new functionality
      - Old documentation affected by the pull request has been updated
      - JavaDoc for public methods has been added
    
    - [x] Tests & Build
      - Functionality added by the pull request is covered by tests
      - `mvn clean verify` has been executed successfully locally or a Travis build has passed
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mushketyk/flink jar-file-close

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/flink/pull/2172.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2172
    
----
commit 33e05d9c5dd65bf99e376b6b788d6a8d0fe2d94a
Author: Ivan Mushketyk <iv...@gmail.com>
Date:   2016-06-27T21:30:08Z

    [FLINK-4096] Ensure JarOutputStream is always closed

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2172: [FLINK-4096] Ensure JarOutputStream is always closed

Posted by zentol <gi...@git.apache.org>.
Github user zentol commented on the issue:

    https://github.com/apache/flink/pull/2172
  
    no, you are correct.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2172: [FLINK-4096] Ensure JarOutputStream is always clos...

Posted by zentol <gi...@git.apache.org>.
Github user zentol commented on a diff in the pull request:

    https://github.com/apache/flink/pull/2172#discussion_r69295166
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/util/JarFileCreator.java ---
    @@ -189,33 +189,33 @@ public synchronized void createJarFile() throws IOException {
     			this.outputFile.delete();
     		}
     
    -		final JarOutputStream jos = new JarOutputStream(new FileOutputStream(this.outputFile), new Manifest());
    -		final Iterator<Class<?>> it = this.classSet.iterator();
    -		while (it.hasNext()) {
    +		try ( JarOutputStream jos = new JarOutputStream(new FileOutputStream(this.outputFile), new Manifest())) {
    +			final Iterator<Class<?>> it = this.classSet.iterator();
    +			while (it.hasNext()) {
     
    -			final Class<?> clazz = it.next();
    -			final String entry = clazz.getName().replace('.', '/') + CLASS_EXTENSION;
    +				final Class<?> clazz = it.next();
    +				final String entry = clazz.getName().replace('.', '/') + CLASS_EXTENSION;
     
    -			jos.putNextEntry(new JarEntry(entry));
    +				jos.putNextEntry(new JarEntry(entry));
     
    -			String name = clazz.getName();
    -			int n = name.lastIndexOf('.');
    -			String className = null;
    -			if (n > -1) {
    -				className = name.substring(n + 1, name.length());
    -			}
    -			//Using the part after last dot instead of class.getSimpleName() could resolve the problem of inner class.
    -			final InputStream classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
    +				String name = clazz.getName();
    +				int n = name.lastIndexOf('.');
    +				String className = null;
    +				if (n > -1) {
    +					className = name.substring(n + 1, name.length());
    +				}
    +				//Using the part after last dot instead of class.getSimpleName() could resolve the problem of inner class.
    +				final InputStream classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
     
    -			int num = classInputStream.read(buf);
    -			while (num != -1) {
    -				jos.write(buf, 0, num);
    -				num = classInputStream.read(buf);
    -			}
    +				int num = classInputStream.read(buf);
    +				while (num != -1) {
    +					jos.write(buf, 0, num);
    +					num = classInputStream.read(buf);
    +				}
     
    -			classInputStream.close();
    -			jos.closeEntry();
    +				classInputStream.close();
    +				jos.closeEntry();
    +			}
     		}
    -		jos.close();
    --- End diff --
    
    close() is now never called.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2172: [FLINK-4096] Ensure JarOutputStream is always closed

Posted by mushketyk <gi...@git.apache.org>.
Github user mushketyk commented on the issue:

    https://github.com/apache/flink/pull/2172
  
    @zentol Can you merge this PR if you find it useful?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink issue #2172: [FLINK-4096] Ensure JarOutputStream is always closed

Posted by mushketyk <gi...@git.apache.org>.
Github user mushketyk commented on the issue:

    https://github.com/apache/flink/pull/2172
  
    Since jos is now used in try-with-resource, I assume it will be called in any case:
    https://github.com/apache/flink/pull/2172/files#diff-966966a476efb23e920314f9bf266539R192
    
    Am I missing something?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] flink pull request #2172: [FLINK-4096] Ensure JarOutputStream is always clos...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/flink/pull/2172


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---