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 2023/12/01 14:28:43 UTC
(commons-validator) 15/23: Better error handling
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-validator.git
commit 5dd59ef910b3c83cb13ba07b32880ff0c9e813e0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 1 08:32:48 2023 -0500
Better error handling
---
.../java/org/apache/commons/validator/ValidatorAction.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/apache/commons/validator/ValidatorAction.java b/src/main/java/org/apache/commons/validator/ValidatorAction.java
index be58ceea..b3ca4c52 100644
--- a/src/main/java/org/apache/commons/validator/ValidatorAction.java
+++ b/src/main/java/org/apache/commons/validator/ValidatorAction.java
@@ -558,13 +558,17 @@ public class ValidatorAction implements Serializable {
* @param name The resource name
* @return An input stream for reading the resource, or {@code null} if the resource could not be found
*/
+ @SuppressWarnings("resource") // Caller closes
private InputStream openInputStream(final String javaScriptFileName, ClassLoader classLoader) {
InputStream is = null;
if (classLoader != null) {
is = classLoader.getResourceAsStream(javaScriptFileName);
}
if (is == null) {
- return getClass().getResourceAsStream(javaScriptFileName);
+ is = getClass().getResourceAsStream(javaScriptFileName);
+ }
+ if (is == null) {
+ getLog().debug(" Unable to read javascript name " + javaScriptFileName);
}
return is;
}
@@ -581,12 +585,7 @@ public class ValidatorAction implements Serializable {
classLoader = getClass().getClassLoader();
}
try (InputStream is = openInputStream(javaScriptFileName, classLoader)) {
- if (is == null) {
- getLog().debug(" Unable to read javascript name " + javaScriptFileName);
- return null;
- }
final StringBuilder buffer = new StringBuilder();
- // TODO encoding
try (BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line = null;
while ((line = reader.readLine()) != null) {