Skip to content

Commit 6d8ba65

Browse files
committed
Merge branch '2.1.x'
Closes gh-17276
2 parents b64d8df + a5ae1de commit 6d8ba65

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ void urlWithQuery() throws MalformedURLException {
156156
void fallbackToJdksJarUrlStreamHandler(@TempDir File tempDir) throws Exception {
157157
File testJar = new File(tempDir, "test.jar");
158158
TestJarCreator.createTestJar(testJar);
159-
URLConnection connection = new URL(null, "jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
160-
this.handler).openConnection();
159+
URLConnection connection = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/", this.handler)
160+
.openConnection();
161161
assertThat(connection).isInstanceOf(JarURLConnection.class);
162162
((JarURLConnection) connection).getJarFile().close();
163-
URLConnection jdkConnection = new URL(null, "jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
163+
URLConnection jdkConnection = new URL(null, "jar:file:" + testJar.toURI().toURL() + "!/nested.jar!/",
164164
this.handler).openConnection();
165165
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
166166
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void tearDown() throws Exception {
6060

6161
@Test
6262
void connectionToRootUsingAbsoluteUrl() throws Exception {
63-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/");
63+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
6464
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
6565
}
6666

@@ -72,7 +72,7 @@ void connectionToRootUsingRelativeUrl() throws Exception {
7272

7373
@Test
7474
void connectionToEntryUsingAbsoluteUrl() throws Exception {
75-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
75+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
7676
try (InputStream input = JarURLConnection.get(url, this.jarFile).getInputStream()) {
7777
assertThat(input).hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
7878
}
@@ -88,15 +88,15 @@ void connectionToEntryUsingRelativeUrl() throws Exception {
8888

8989
@Test
9090
void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix() throws Exception {
91-
URL url = new URL("jar:file:/" + getAbsolutePath() + "!/1.dat");
91+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
9292
try (InputStream input = JarURLConnection.get(url, this.jarFile).getInputStream()) {
9393
assertThat(input).hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
9494
}
9595
}
9696

9797
@Test
9898
void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
99-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
99+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
100100
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
101101
try (InputStream input = connection.getInputStream()) {
102102
assertThat(input).hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
@@ -116,7 +116,7 @@ void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
116116

117117
@Test
118118
void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
119-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
119+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
120120
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
121121
try (InputStream input = JarURLConnection.get(url, nested).getInputStream()) {
122122
assertThat(input).hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
@@ -136,7 +136,7 @@ void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws Excepti
136136

137137
@Test
138138
void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext() throws Exception {
139-
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
139+
URL url = new URL(new URL("jar", null, -1, this.rootJarFile.toURI().toURL() + "!/nested.jar!/", new Handler()),
140140
"/3.dat");
141141
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
142142
try (InputStream input = JarURLConnection.get(url, nested).getInputStream()) {
@@ -167,7 +167,7 @@ void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
167167

168168
@Test
169169
void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
170-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/w.jar!/3.dat");
170+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/w.jar!/3.dat");
171171
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
172172
assertThatExceptionOfType(FileNotFoundException.class)
173173
.isThrownBy(JarURLConnection.get(url, nested)::getInputStream);
@@ -176,7 +176,7 @@ void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Ex
176176

177177
@Test
178178
void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
179-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
179+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
180180
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
181181
JarURLConnection connection = JarURLConnection.get(url, nested);
182182
assertThat(connection.getContentLength()).isEqualTo(1);
@@ -185,7 +185,7 @@ void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
185185

186186
@Test
187187
void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
188-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
188+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
189189
try (JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))) {
190190
JarURLConnection connection = JarURLConnection.get(url, nested);
191191
assertThat(connection.getContentLengthLong()).isEqualTo(1);
@@ -194,7 +194,7 @@ void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
194194

195195
@Test
196196
void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
197-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
197+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
198198
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
199199
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
200200
}
@@ -220,10 +220,6 @@ void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
220220
.isEqualTo("\u00e1/b/\u00c7.class");
221221
}
222222

223-
private String getAbsolutePath() {
224-
return this.rootJarFile.getAbsolutePath().replace('\\', '/');
225-
}
226-
227223
private String getRelativePath() {
228224
return this.rootJarFile.getPath().replace('\\', '/');
229225
}

0 commit comments

Comments
 (0)