[java-identity-provider] branch master updated: OSJ-285 Ensure Closeeable interfaces are.

Rod Widdowson rdw at steadingsoftware.com
Sat Feb 15 08:36:21 EST 2020


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=099d15a950bd25ea6eaa1d1c8cb846dd1532dd4f

The following commit(s) were added to refs/heads/master by this push:
       new  099d15a   OSJ-285 Ensure Closeeable interfaces are.
099d15a is described below

commit 099d15a950bd25ea6eaa1d1c8cb846dd1532dd4f
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Sat Feb 15 13:29:32 2020 +0000

    OSJ-285 Ensure Closeeable interfaces are.
    
    https://issues.shibboleth.net/jira/browse/OSJ-285
    
    Installer code.
---
 .../idp/installer/InstallerPropertiesImpl.java     |  4 +--
 .../idp/installer/PropertiesWithComments.java      | 39 +++++++++++-----------
 .../net/shibboleth/idp/installer/V4Install.java    | 29 +++++++++++-----
 .../metadata/impl/MetadataGeneratorImpl.java       |  5 +++
 4 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
index 2ea5363..1572b1a 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/InstallerPropertiesImpl.java
@@ -241,8 +241,8 @@ public class InstallerPropertiesImpl extends AbstractInitializableComponent impl
 
             /* The file specified in the system file idp.property.file (if present). */
             final File idpPropertyFile = file.toFile();
-            try {
-                installerProperties.load(new FileInputStream(idpPropertyFile));
+            try(final FileInputStream stream = new FileInputStream(idpPropertyFile)) {
+                installerProperties.load(stream);
             } catch (final IOException e) {
                 log.error("Could not load {}: {}", file.toAbsolutePath(), e.getMessage());
                 throw new ComponentInitializationException(e);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
index 101eeda..f71ea31 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/PropertiesWithComments.java
@@ -149,29 +149,30 @@ public final class PropertiesWithComments {
      * @throws IOException if readline fails
      */
     public void load(final InputStream input) throws IOException {
-        final BufferedReader reader = new BufferedReader(new InputStreamReader(input));
-        contents = new ArrayList<>();
-        properties = new HashMap<>();
-
-        String s = reader.readLine();
-
-        while (s != null) {
-            final String what = StringSupport.trimOrNull(s);
-            if (what == null) {
-                contents.add("");
-            } else if (what.startsWith("#")) {
-                if (what.contains("=")) {
-                    addCommentedProperty(s, true);
+        try(final BufferedReader reader = new BufferedReader(new InputStreamReader(input))) {
+            contents = new ArrayList<>();
+            properties = new HashMap<>();
+    
+            String s = reader.readLine();
+    
+            while (s != null) {
+                final String what = StringSupport.trimOrNull(s);
+                if (what == null) {
+                    contents.add("");
+                } else if (what.startsWith("#")) {
+                    if (what.contains("=")) {
+                        addCommentedProperty(s, true);
+                    } else {
+                        contents.add(what);
+                    }
                 } else {
-                    contents.add(what);
+    
+                    addCommentedProperty(s, false);
                 }
-            } else {
-
-                addCommentedProperty(s, false);
+                s = reader.readLine();
             }
-            s = reader.readLine();
+            loadedData = true;
         }
-        loadedData = true;
     }
 
     /**
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
index 918b1d1..63f61a4 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/V4Install.java
@@ -161,8 +161,9 @@ public class V4Install extends AbstractInitializableComponent {
             final Properties vers = new Properties();
             vers.setProperty(InstallerSupport.VERSION_NAME, currentVersion);
             vers.setProperty(InstallerSupport.PREVIOUS_VERSION_NAME, installedVersion==null?"":installedVersion);
-            final OutputStream out = new FileOutputStream(versFile.toFile());
-            vers.store(out, "Version file written at " + Instant.now());
+            try(final OutputStream out = new FileOutputStream(versFile.toFile())) {
+                vers.store(out, "Version file written at " + Instant.now());
+            }
         } catch (final IOException e) {
             log.error("Couldn't write version file: {}", e.getMessage());
             throw new BuildException("Couldn't write versioning information", e);
@@ -227,14 +228,20 @@ public class V4Install extends AbstractInitializableComponent {
                     if (!installerProps.isNoTidy()) {
                         mergeFile.deleteOnExit();
                     }
-                    replacements.load(new FileInputStream(mergeFile));
+                    try (final FileInputStream stream = new FileInputStream(mergeFile)) {
+                        replacements.load(stream);
+                    }
                 } else {
                     replacements = getIdPReplacements(sealerCreated);
                     log.debug("Creating {} from {} and {}", target, source, replacements.keySet());
                 }
-                propertiesToReWrite.load(new FileInputStream(source.toFile()));
+                try (final FileInputStream stream = new FileInputStream(source.toFile())) {
+                    propertiesToReWrite.load(stream);
+                }
                 propertiesToReWrite.replaceProperties(replacements);
-                propertiesToReWrite.store(new FileOutputStream(target.toFile()));
+                try (final FileOutputStream stream = new FileOutputStream(target.toFile())) {
+                    propertiesToReWrite.store(stream);
+                }
             } catch (final IOException e) {
                 throw new BuildException("Failed to generate idp.properties", e);
             }
@@ -259,10 +266,16 @@ public class V4Install extends AbstractInitializableComponent {
                 if (!installerProps.isNoTidy()) {
                     mergeFile.deleteOnExit();
                 }
-                replacements.load(new FileInputStream(mergeFile));
-                propertiesToReWrite.load(new FileInputStream(source.toFile()));
+                try (final FileInputStream stream = new FileInputStream(mergeFile)) {
+                    replacements.load(stream);
+                }
+                try (final FileInputStream stream = new FileInputStream(source.toFile())) {
+                    propertiesToReWrite.load(stream);
+                }
                 propertiesToReWrite.replaceProperties(replacements);
-                propertiesToReWrite.store(new FileOutputStream(target.toFile()));
+                try (final FileOutputStream stream = new FileOutputStream(target.toFile())) {
+                    propertiesToReWrite.store(stream);
+                }
             } catch (final IOException e) {
                 throw new BuildException("Failed to generate ldap.properties", e);
             }
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
index d56f798..9db9a40 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/metadata/impl/MetadataGeneratorImpl.java
@@ -270,6 +270,11 @@ public class MetadataGeneratorImpl extends AbstractInitializableComponent implem
             writer.flush();
             writer.close();
         } catch (final IOException e) {
+            try {
+                writer.close();
+            } catch (final IOException e1) {
+                // Ignore
+            }
             throw new BuildException(e);
         }
     }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list