You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2023/06/12 09:28:49 UTC

[santuario-xml-security-java] branch 2.3.x-fixes updated: Cleaner Init code (#173)

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 2.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/santuario-xml-security-java.git


The following commit(s) were added to refs/heads/2.3.x-fixes by this push:
     new 0eb335da Cleaner Init code (#173)
0eb335da is described below

commit 0eb335da08486752067b114f325d1598e22b42a5
Author: David Matějček <da...@omnifish.ee>
AuthorDate: Mon Jun 12 10:56:11 2023 +0200

    Cleaner Init code (#173)
    
    - more reliable input stream management - try-with
    
    Signed-off-by: David Matějček <da...@omnifish.ee>
---
 src/main/java/org/apache/xml/security/Init.java | 35 ++++++++++---------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/xml/security/Init.java b/src/main/java/org/apache/xml/security/Init.java
index 64d3c2e2..d3250752 100644
--- a/src/main/java/org/apache/xml/security/Init.java
+++ b/src/main/java/org/apache/xml/security/Init.java
@@ -75,28 +75,21 @@ public class Init {
         if (alreadyInitialized) {
             return;
         }
-
-        InputStream is =    //NOPMD
-            AccessController.doPrivileged(
-                (PrivilegedAction<InputStream>)
-                    () -> {
-                        String cfile =
-                            System.getProperty("org.apache.xml.security.resource.config");
-                        if (cfile == null) {
-                            return null;
-                        }
-                        return ClassLoaderUtils.getResourceAsStream(cfile, Init.class);
-                    }
-                );
-        if (is == null) {
-            dynamicInit();
-        } else {
-            fileInit(is);
-            try {
-                is.close();
-            } catch (IOException ex) {
-                LOG.warn(ex.getMessage());
+        PrivilegedAction<InputStream> action = () -> {
+            String cfile = System.getProperty("org.apache.xml.security.resource.config");
+            if (cfile == null) {
+                return null;
+            }
+            return ClassLoaderUtils.getResourceAsStream(cfile, Init.class);
+        };
+        try (InputStream is = AccessController.doPrivileged(action)) {
+            if (is == null) {
+                dynamicInit();
+            } else {
+                fileInit(is);
             }
+        } catch (IOException ex) {
+            LOG.warn(ex.getMessage(), ex);
         }
 
         alreadyInitialized = true;