You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/03/19 15:50:36 UTC
[commons-crypto] 03/04: Fail early when the resource is not found which makes SpotBugs happy on Java 17.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-crypto.git
commit 3f5a0f0ffe050a147a1fc5f9af625fa44dd09496
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Mar 19 11:37:13 2022 -0400
Fail early when the resource is not found which makes SpotBugs happy on
Java 17.
---
.../java/org/apache/commons/crypto/utils/Utils.java | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/commons/crypto/utils/Utils.java b/src/main/java/org/apache/commons/crypto/utils/Utils.java
index 178c0bb..fbc1a3f 100644
--- a/src/main/java/org/apache/commons/crypto/utils/Utils.java
+++ b/src/main/java/org/apache/commons/crypto/utils/Utils.java
@@ -19,6 +19,7 @@ package org.apache.commons.crypto.utils;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -61,15 +62,14 @@ public final class Utils {
private static Properties createDefaultProperties() {
// default to system
final Properties defaultedProps = new Properties(System.getProperties());
+ final URL url = Thread.currentThread().getContextClassLoader().getResource(SYSTEM_PROPERTIES_FILE);
+ if (url == null) {
+ // Fail early when the resource is not found which makes SpotBugs happy on Java 17.
+ return defaultedProps;
+ }
try {
final Properties fileProps = new Properties();
- try (InputStream is = Thread.currentThread().getContextClassLoader()
- .getResourceAsStream(SYSTEM_PROPERTIES_FILE)) {
-
- if (is == null) {
- return defaultedProps; // no configuration file is found
- }
- // Load property file
+ try (InputStream is = url.openStream()) {
fileProps.load(is);
}
final Enumeration<?> names = fileProps.propertyNames();
@@ -81,9 +81,7 @@ public final class Utils {
}
}
} catch (final Exception ex) {
- System.err.println("Could not load '"
- + SYSTEM_PROPERTIES_FILE
- + "' from classpath: " + ex.toString());
+ System.err.println("Could not load '" + SYSTEM_PROPERTIES_FILE + "' from classpath: " + ex.toString());
}
return defaultedProps;
}