Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/commons-text into 1.5
diff --git a/src/main/java/org/apache/commons/text/lookup/Base64StringLookup.java b/src/main/java/org/apache/commons/text/lookup/Base64StringLookup.java
index a4651bd..e1607a4 100644
--- a/src/main/java/org/apache/commons/text/lookup/Base64StringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/Base64StringLookup.java
@@ -17,6 +17,7 @@
package org.apache.commons.text.lookup;
+import java.nio.charset.StandardCharsets;
import java.util.Base64;
/**
@@ -40,7 +41,7 @@
@Override
public String lookup(final String key) {
- return new String(Base64.getDecoder().decode(key));
+ return new String(Base64.getDecoder().decode(key), StandardCharsets.ISO_8859_1);
}
}
diff --git a/src/main/java/org/apache/commons/text/lookup/ConstantStringLookup.java b/src/main/java/org/apache/commons/text/lookup/ConstantStringLookup.java
index 96e7855..466e471 100644
--- a/src/main/java/org/apache/commons/text/lookup/ConstantStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/ConstantStringLookup.java
@@ -120,8 +120,7 @@
if (clazz == null) {
return null;
}
- final Field field = clazz.getField(fieldName);
- return field == null ? null : field.get(null);
+ return clazz.getField(fieldName).get(null);
}
/**
diff --git a/src/main/java/org/apache/commons/text/lookup/PropertiesStringLookup.java b/src/main/java/org/apache/commons/text/lookup/PropertiesStringLookup.java
index 6c6acc9..edae89a 100644
--- a/src/main/java/org/apache/commons/text/lookup/PropertiesStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/PropertiesStringLookup.java
@@ -17,6 +17,7 @@
package org.apache.commons.text.lookup;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;
@@ -77,7 +78,9 @@
final String propertyKey = substringAfter(key, "::");
try {
final Properties properties = new Properties();
- properties.load(Files.newInputStream(Paths.get(documentPath)));
+ try (final InputStream inputStream = Files.newInputStream(Paths.get(documentPath))) {
+ properties.load(inputStream);
+ }
return properties.getProperty(propertyKey);
} catch (final Exception e) {
throw IllegalArgumentExceptions.format(e, "Error looking up properties [%s] and key [%s].", documentPath,
diff --git a/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java b/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
index 55a2807..8e4e369 100644
--- a/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/UrlDecoderStringLookup.java
@@ -46,7 +46,7 @@
public String lookup(final String key) {
final String enc = StandardCharsets.UTF_8.name();
try {
- return new String(URLDecoder.decode(key, enc));
+ return URLDecoder.decode(key, enc);
} catch (final UnsupportedEncodingException e) {
throw IllegalArgumentExceptions.format(e, "%s: source=%s, encoding=%s", e, key, enc);
}
diff --git a/src/main/java/org/apache/commons/text/lookup/UrlEncoderStringLookup.java b/src/main/java/org/apache/commons/text/lookup/UrlEncoderStringLookup.java
index fdc2c1f..43ba870 100644
--- a/src/main/java/org/apache/commons/text/lookup/UrlEncoderStringLookup.java
+++ b/src/main/java/org/apache/commons/text/lookup/UrlEncoderStringLookup.java
@@ -45,7 +45,7 @@
public String lookup(final String key) {
final String enc = StandardCharsets.UTF_8.name();
try {
- return new String(URLEncoder.encode(key, enc));
+ return URLEncoder.encode(key, enc);
} catch (final UnsupportedEncodingException e) {
throw IllegalArgumentExceptions.format(e, "%s: source=%s, encoding=%s", e, key, enc);
}