Skip to content

Commit 60e1cc5

Browse files
committed
Merge branch '2.6.x' into 2.7.x
See gh-32085
2 parents 3fcfcc4 + 13bd61b commit 60e1cc5

File tree

9 files changed

+27
-144
lines changed

9 files changed

+27
-144
lines changed

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

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -128,6 +128,9 @@ private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccess
128128
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter,
129129
JarFileType type, Supplier<Manifest> manifestSupplier) throws IOException {
130130
super(rootFile.getFile());
131+
if (System.getSecurityManager() == null) {
132+
super.close();
133+
}
131134
this.rootFile = rootFile;
132135
this.pathFromRoot = pathFromRoot;
133136
CentralDirectoryParser parser = new CentralDirectoryParser();
@@ -139,7 +142,8 @@ private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccess
139142
}
140143
catch (RuntimeException ex) {
141144
try {
142-
close();
145+
this.rootFile.close();
146+
super.close();
143147
}
144148
catch (IOException ioex) {
145149
}
@@ -184,13 +188,8 @@ public void visitEnd() {
184188
JarFileWrapper getWrapper() throws IOException {
185189
JarFileWrapper wrapper = this.wrapper;
186190
if (wrapper == null) {
187-
synchronized (this) {
188-
if (this.wrapper != null) {
189-
return this.wrapper;
190-
}
191-
wrapper = new JarFileWrapper(this);
192-
this.wrapper = wrapper;
193-
}
191+
wrapper = new JarFileWrapper(this);
192+
this.wrapper = wrapper;
194193
}
195194
return wrapper;
196195
}
@@ -356,13 +355,11 @@ public void close() throws IOException {
356355
if (this.closed) {
357356
return;
358357
}
359-
synchronized (this) {
360-
super.close();
361-
if (this.type == JarFileType.DIRECT) {
362-
this.rootFile.close();
363-
}
364-
this.closed = true;
358+
super.close();
359+
if (this.type == JarFileType.DIRECT) {
360+
this.rootFile.close();
365361
}
362+
this.closed = true;
366363
}
367364

368365
private void ensureOpen() {

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -40,6 +40,9 @@ class JarFileWrapper extends AbstractJarFile {
4040
JarFileWrapper(JarFile parent) throws IOException {
4141
super(parent.getRootJarFile().getFile());
4242
this.parent = parent;
43+
if (System.getSecurityManager() == null) {
44+
super.close();
45+
}
4346
}
4447

4548
@Override

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

+2-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -18,7 +18,6 @@
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.FileNotFoundException;
21-
import java.io.FilterInputStream;
2221
import java.io.IOException;
2322
import java.io.InputStream;
2423
import java.io.UnsupportedEncodingException;
@@ -166,7 +165,7 @@ public InputStream getInputStream() throws IOException {
166165
if (inputStream == null) {
167166
throwFileNotFound(this.jarEntryName, this.jarFile);
168167
}
169-
return new ConnectionInputStream(inputStream);
168+
return inputStream;
170169
}
171170

172171
private void throwFileNotFound(Object entry, AbstractJarFile jarFile) throws FileNotFoundException {
@@ -291,19 +290,6 @@ private static JarURLConnection notFound(JarFile jarFile, JarEntryName jarEntryN
291290
return new JarURLConnection(null, jarFile, jarEntryName);
292291
}
293292

294-
private class ConnectionInputStream extends FilterInputStream {
295-
296-
ConnectionInputStream(InputStream in) {
297-
super(in);
298-
}
299-
300-
@Override
301-
public void close() throws IOException {
302-
JarURLConnection.this.jarFile.close();
303-
}
304-
305-
}
306-
307293
/**
308294
* A JarEntryName parsed from a URL String.
309295
*/

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -61,7 +61,6 @@ void setup(@TempDir File temp) throws Exception {
6161
@AfterEach
6262
void cleanup() throws Exception {
6363
this.parent.close();
64-
this.wrapper.close();
6564
}
6665

6766
private File createTempJar(File temp) throws IOException {

spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/build.gradle

+1-15
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ dependencies {
1414
app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")
1515
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
1616
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
17-
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter", configuration: "mavenRepository")
18-
app("org.bouncycastle:bcprov-jdk15on:1.70")
1917

2018
intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))
2119
intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
@@ -41,18 +39,6 @@ task buildApp(type: GradleBuild) {
4139
tasks = ["build"]
4240
}
4341

44-
task syncSignedJarUnpackAppSource(type: org.springframework.boot.build.SyncAppSource) {
45-
sourceDirectory = file("spring-boot-loader-tests-signed-jar-unpack-app")
46-
destinationDirectory = file("${buildDir}/spring-boot-loader-tests-signed-jar-unpack-app")
47-
}
48-
49-
task buildSignedJarUnpackApp(type: GradleBuild) {
50-
dependsOn syncSignedJarUnpackAppSource, syncMavenRepository
51-
dir = "${buildDir}/spring-boot-loader-tests-signed-jar-unpack-app"
52-
startParameter.buildCacheEnabled = false
53-
tasks = ["build"]
54-
}
55-
5642
intTest {
57-
dependsOn buildApp, buildSignedJarUnpackApp
43+
dependsOn buildApp
5844
}

spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/spring-boot-loader-tests-signed-jar-unpack-app/build.gradle

-22
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/spring-boot-loader-tests-signed-jar-unpack-app/settings.gradle

-15
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/spring-boot-loader-tests-signed-jar-unpack-app/src/main/java/org/springframework/boot/loaderapp/LoaderSignedJarTestApplication.java

-36
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java

+7-22
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,25 @@ class LoaderIntegrationTests {
5151
@ParameterizedTest
5252
@MethodSource("javaRuntimes")
5353
void readUrlsWithoutWarning(JavaRuntime javaRuntime) {
54-
try (GenericContainer<?> container = createContainer(javaRuntime, "spring-boot-loader-tests-app")) {
54+
try (GenericContainer<?> container = createContainer(javaRuntime)) {
5555
container.start();
5656
System.out.println(this.output.toUtf8String());
5757
assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
5858
.doesNotContain("illegal").doesNotContain("jar written to temp");
5959
}
6060
}
6161

62-
@ParameterizedTest
63-
@MethodSource("javaRuntimes")
64-
void runSignedJarWhenUnpacked(JavaRuntime javaRuntime) {
65-
try (GenericContainer<?> container = createContainer(javaRuntime,
66-
"spring-boot-loader-tests-signed-jar-unpack-app")) {
67-
container.start();
68-
System.out.println(this.output.toUtf8String());
69-
assertThat(this.output.toUtf8String()).contains("Legion of the Bouncy Castle");
70-
}
71-
}
72-
73-
private GenericContainer<?> createContainer(JavaRuntime javaRuntime, String name) {
62+
private GenericContainer<?> createContainer(JavaRuntime javaRuntime) {
7463
return javaRuntime.getContainer().withLogConsumer(this.output)
75-
.withCopyFileToContainer(findApplication(name), "/app.jar")
64+
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
7665
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
7766
.withCommand("java", "-jar", "app.jar");
7867
}
7968

80-
private MountableFile findApplication(String name) {
81-
return MountableFile.forHostPath(findJarFile(name).toPath());
82-
}
83-
84-
private File findJarFile(String name) {
85-
String path = String.format("build/%1$s/build/libs/%1$s.jar", name);
86-
File jar = new File(path);
87-
Assert.state(jar.isFile(), () -> "Could not find " + path + ". Have you built it?");
69+
private File findApplication() {
70+
String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-loader-tests-app");
71+
File jar = new File(name);
72+
Assert.state(jar.isFile(), () -> "Could not find " + name + ". Have you built it?");
8873
return jar;
8974
}
9075

0 commit comments

Comments
 (0)