Skip to content

Commit 33a81e8

Browse files
hengyunabcwilkinsona
authored andcommitted
Avoid null handler package in JarFile protocol handler registration
Closes gh-6759
1 parent 63b8e82 commit 33a81e8

File tree

2 files changed

+13
-1
lines changed
  • spring-boot-tools/spring-boot-loader/src

2 files changed

+13
-1
lines changed

spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarFile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public String getName() {
449449
* {@link URLStreamHandler} will be located to deal with jar URLs.
450450
*/
451451
public static void registerUrlProtocolHandler() {
452-
String handlers = System.getProperty(PROTOCOL_HANDLER);
452+
String handlers = System.getProperty(PROTOCOL_HANDLER, "");
453453
System.setProperty(PROTOCOL_HANDLER, ("".equals(handlers) ? HANDLERS_PACKAGE
454454
: handlers + "|" + HANDLERS_PACKAGE));
455455
resetCachedUrlHandlers();

spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarFileTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
import org.springframework.util.FileCopyUtils;
4444
import org.springframework.util.StreamUtils;
4545

46+
import static org.hamcrest.Matchers.containsString;
4647
import static org.hamcrest.Matchers.equalTo;
4748
import static org.hamcrest.Matchers.greaterThan;
4849
import static org.hamcrest.Matchers.instanceOf;
4950
import static org.hamcrest.Matchers.is;
51+
import static org.hamcrest.Matchers.not;
5052
import static org.hamcrest.Matchers.notNullValue;
5153
import static org.hamcrest.Matchers.nullValue;
5254
import static org.hamcrest.Matchers.sameInstance;
@@ -63,6 +65,9 @@
6365
* @author Andy Wilkinson
6466
*/
6567
public class JarFileTests {
68+
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
69+
70+
private static final String HANDLERS_PACKAGE = "org.springframework.boot.loader";
6671

6772
@Rule
6873
public ExpectedException thrown = ExpectedException.none();
@@ -453,4 +458,11 @@ public void cannotLoadMissingJar() throws Exception {
453458
url.openConnection().getInputStream();
454459
}
455460

461+
@Test
462+
public void registerUrlProtocolHandler() {
463+
JarFile.registerUrlProtocolHandler();
464+
String protocolHandler = System.getProperty(PROTOCOL_HANDLER);
465+
assertThat(protocolHandler, containsString(HANDLERS_PACKAGE));
466+
assertThat(protocolHandler, not(containsString("null")));
467+
}
456468
}

0 commit comments

Comments
 (0)