]> source.dussan.org Git - jgit.git/commitdiff
[infer] Fix resource leak in ManifestParser 66/87366/5
authorMatthias Sohn <matthias.sohn@sap.com>
Sun, 18 Dec 2016 11:06:55 +0000 (12:06 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Sun, 18 Dec 2016 22:02:47 +0000 (23:02 +0100)
Bug: 509385
Change-Id: Icfe58ac2e5344546448a55ad14ec082356be968c
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java

index 2370ae14c7608df2ec85783753436a3a7939c15d..8a35d35fea5c9cc6f1b6e255a8b0ce21c8529290 100644 (file)
@@ -215,10 +215,13 @@ public class ManifestParser extends DefaultHandler {
                                                attributes.getValue("dest"))); //$NON-NLS-1$
                } else if ("include".equals(qName)) { //$NON-NLS-1$
                        String name = attributes.getValue("name"); //$NON-NLS-1$
-                       InputStream is = null;
                        if (includedReader != null) {
-                               try {
-                                       is = includedReader.readIncludeFile(name);
+                               try (InputStream is = includedReader.readIncludeFile(name)) {
+                                       if (is == null) {
+                                               throw new SAXException(
+                                                               RepoText.get().errorIncludeNotImplemented);
+                                       }
+                                       read(is);
                                } catch (Exception e) {
                                        throw new SAXException(MessageFormat.format(
                                                        RepoText.get().errorIncludeFile, name), e);
@@ -226,22 +229,13 @@ public class ManifestParser extends DefaultHandler {
                        } else if (filename != null) {
                                int index = filename.lastIndexOf('/');
                                String path = filename.substring(0, index + 1) + name;
-                               try {
-                                       is = new FileInputStream(path);
+                               try (InputStream is = new FileInputStream(path)) {
+                                       read(is);
                                } catch (IOException e) {
                                        throw new SAXException(MessageFormat.format(
                                                        RepoText.get().errorIncludeFile, path), e);
                                }
                        }
-                       if (is == null) {
-                               throw new SAXException(
-                                               RepoText.get().errorIncludeNotImplemented);
-                       }
-                       try {
-                               read(is);
-                       } catch (IOException e) {
-                               throw new SAXException(e);
-                       }
                }
        }