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 08:56:16 UTC
[santuario-xml-security-java] branch main updated: Cleaner Init code (#173)
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/santuario-xml-security-java.git
The following commit(s) were added to refs/heads/main by this push:
new 12fcef29 Cleaner Init code (#173)
12fcef29 is described below
commit 12fcef2964646115223c012d4daf30a2f6b2851f
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;