Skip to content

Commit a0f3aaf

Browse files
authored
Merge pull request #1142 from jglick/duplicate-keys
Restore check for duplicate keys in `*.properties`
2 parents 6e1dd03 + a2fa598 commit a0f3aaf

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/main/java/org/jvnet/hudson/test/injected/InjectedTestBase.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.io.File;
1313
import java.io.IOException;
1414
import java.io.InputStream;
15+
import java.io.InputStreamReader;
1516
import java.net.URI;
1617
import java.net.URL;
1718
import java.nio.ByteBuffer;
@@ -25,7 +26,6 @@
2526
import java.util.Map;
2627
import java.util.Objects;
2728
import java.util.Properties;
28-
import java.util.PropertyResourceBundle;
2929
import java.util.jar.JarEntry;
3030
import java.util.jar.JarFile;
3131
import java.util.stream.Stream;
@@ -176,21 +176,21 @@ public synchronized Object put(Object key, Object value) {
176176
}
177177
};
178178

179+
boolean isUtf8;
179180
try (InputStream is = resource.openStream()) {
180181
byte[] contents = is.readAllBytes();
181-
if (!isEncoded(contents, StandardCharsets.US_ASCII)) {
182-
boolean isUtf8 = isEncoded(contents, StandardCharsets.UTF_8);
182+
if (isEncoded(contents, StandardCharsets.US_ASCII)) {
183+
isUtf8 = false;
184+
} else {
185+
isUtf8 = isEncoded(contents, StandardCharsets.UTF_8);
183186
boolean isIso88591 = isEncoded(contents, StandardCharsets.ISO_8859_1);
184187
assertTrue(isUtf8 || isIso88591, resource + " must be either valid UTF-8 or valid ISO-8859-1.");
185188
}
186189
}
187190

188-
try (InputStream is = resource.openStream()) {
189-
PropertyResourceBundle propertyResourceBundle = new PropertyResourceBundle(is);
190-
propertyResourceBundle
191-
.getKeys()
192-
.asIterator()
193-
.forEachRemaining(key -> props.setProperty(key, propertyResourceBundle.getString(key)));
191+
try (var is = resource.openStream();
192+
var r = new InputStreamReader(is, isUtf8 ? StandardCharsets.UTF_8 : StandardCharsets.ISO_8859_1)) {
193+
props.load(r);
194194
}
195195
}
196196

0 commit comments

Comments
 (0)