diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 18eb98848d..908d7bc511 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -20,14 +20,14 @@ import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.Charset; import java.util.jar.Manifest; /** * {@link java.net.JarURLConnection} used to support {@link JarFile#getUrl()}. - * + * * @author Phillip Webb */ class JarURLConnection extends java.net.JarURLConnection { @@ -169,25 +169,21 @@ class JarURLConnection extends java.net.JarURLConnection { if ((length == 0) || (source.indexOf('%') < 0)) { return source; } - try { - ByteArrayOutputStream bos = new ByteArrayOutputStream(length); - for (int i = 0; i < length; i++) { - int ch = source.charAt(i); - if (ch == '%') { - if ((i + 2) >= length) { - throw new IllegalArgumentException("Invalid encoded sequence \"" - + source.substring(i) + "\""); - } - ch = decodeEscapeSequence(source, i); - i += 2; + ByteArrayOutputStream bos = new ByteArrayOutputStream(length); + for (int i = 0; i < length; i++) { + int ch = source.charAt(i); + if (ch == '%') { + if ((i + 2) >= length) { + throw new IllegalArgumentException("Invalid encoded sequence \"" + + source.substring(i) + "\""); } - bos.write(ch); + ch = decodeEscapeSequence(source, i); + i += 2; } - return new String(bos.toByteArray(), "UTF-8"); - } - catch (UnsupportedEncodingException ex) { - throw new IllegalStateException(ex); + bos.write(ch); } + return new String(bos.toByteArray(), Charset.defaultCharset()); + } private static char decodeEscapeSequence(String source, int i) {