diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java index ab0a447619..7a3ee76a4f 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java @@ -376,7 +376,7 @@ public class JarFile extends java.util.jar.JarFile { * {@link URLStreamHandler} will be located to deal with jar URLs. */ public static void registerUrlProtocolHandler() { - String handlers = System.getProperty(PROTOCOL_HANDLER); + String handlers = System.getProperty(PROTOCOL_HANDLER, ""); System.setProperty(PROTOCOL_HANDLER, ("".equals(handlers) ? HANDLERS_PACKAGE : handlers + "|" + HANDLERS_PACKAGE)); resetCachedUrlHandlers(); diff --git a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java index d238656d30..f4cc67b9ff 100644 --- a/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java +++ b/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java @@ -54,6 +54,9 @@ import static org.mockito.Mockito.verify; * @author Andy Wilkinson */ public class JarFileTests { + private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs"; + + private static final String HANDLERS_PACKAGE = "org.springframework.boot.loader"; @Rule public ExpectedException thrown = ExpectedException.none(); @@ -420,4 +423,42 @@ public class JarFileTests { url.openConnection().getInputStream(); } + @Test + public void registerUrlProtocolHandlerWithNoExistingRegistration() { + String original = System.getProperty(PROTOCOL_HANDLER); + try { + System.clearProperty(PROTOCOL_HANDLER); + JarFile.registerUrlProtocolHandler(); + String protocolHandler = System.getProperty(PROTOCOL_HANDLER); + assertThat(protocolHandler).isEqualTo(HANDLERS_PACKAGE); + } + finally { + if (original == null) { + System.clearProperty(PROTOCOL_HANDLER); + } + else { + System.setProperty(PROTOCOL_HANDLER, original); + } + } + } + + @Test + public void registerUrlProtocolHandlerAddsToExistingRegistration() { + String original = System.getProperty(PROTOCOL_HANDLER); + try { + System.setProperty(PROTOCOL_HANDLER, "com.example"); + JarFile.registerUrlProtocolHandler(); + String protocolHandler = System.getProperty(PROTOCOL_HANDLER); + assertThat(protocolHandler).isEqualTo("com.example|" + HANDLERS_PACKAGE); + } + finally { + if (original == null) { + System.clearProperty(PROTOCOL_HANDLER); + } + else { + System.setProperty(PROTOCOL_HANDLER, original); + } + } + } + }