Skip to content

Commit eb1c349

Browse files
committed
Polish “Avoid null handler package in JarFile protocol handler registration”
See gh-6759
1 parent 33a81e8 commit eb1c349

File tree

2 files changed

+37
-8
lines changed
  • spring-boot-tools/spring-boot-loader/src

2 files changed

+37
-8
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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

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

46-
import static org.hamcrest.Matchers.containsString;
4746
import static org.hamcrest.Matchers.equalTo;
4847
import static org.hamcrest.Matchers.greaterThan;
4948
import static org.hamcrest.Matchers.instanceOf;
5049
import static org.hamcrest.Matchers.is;
51-
import static org.hamcrest.Matchers.not;
5250
import static org.hamcrest.Matchers.notNullValue;
5351
import static org.hamcrest.Matchers.nullValue;
5452
import static org.hamcrest.Matchers.sameInstance;
@@ -459,10 +457,41 @@ public void cannotLoadMissingJar() throws Exception {
459457
}
460458

461459
@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")));
460+
public void registerUrlProtocolHandlerWithNoExistingRegistration() {
461+
String original = System.getProperty(PROTOCOL_HANDLER);
462+
try {
463+
System.clearProperty(PROTOCOL_HANDLER);
464+
JarFile.registerUrlProtocolHandler();
465+
String protocolHandler = System.getProperty(PROTOCOL_HANDLER);
466+
assertThat(protocolHandler, equalTo(HANDLERS_PACKAGE));
467+
}
468+
finally {
469+
if (original == null) {
470+
System.clearProperty(PROTOCOL_HANDLER);
471+
}
472+
else {
473+
System.setProperty(PROTOCOL_HANDLER, original);
474+
}
475+
}
467476
}
477+
478+
@Test
479+
public void registerUrlProtocolHandlerAddsToExistingRegistration() {
480+
String original = System.getProperty(PROTOCOL_HANDLER);
481+
try {
482+
System.setProperty(PROTOCOL_HANDLER, "com.example");
483+
JarFile.registerUrlProtocolHandler();
484+
String protocolHandler = System.getProperty(PROTOCOL_HANDLER);
485+
assertThat(protocolHandler, equalTo("com.example|" + HANDLERS_PACKAGE));
486+
}
487+
finally {
488+
if (original == null) {
489+
System.clearProperty(PROTOCOL_HANDLER);
490+
}
491+
else {
492+
System.setProperty(PROTOCOL_HANDLER, original);
493+
}
494+
}
495+
}
496+
468497
}

0 commit comments

Comments
 (0)