Skip to content

Commit 2578e81

Browse files
filiphrsnicoll
authored andcommitted
Fix nested archive paths logging in PropertiesLauncher
See gh-50968 Signed-off-by: Filip Hrisafov <filip.hrisafov@gmail.com>
1 parent 629a01a commit 2578e81

2 files changed

Lines changed: 13 additions & 16 deletions

File tree

loader/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/PropertiesLauncher.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ public class PropertiesLauncher extends Launcher {
136136

137137
private final File homeDirectory;
138138

139-
private final List<String> paths;
140-
141139
private final Properties properties = new Properties();
142140

143141
public PropertiesLauncher() throws Exception {
@@ -148,7 +146,6 @@ public PropertiesLauncher() throws Exception {
148146
this.archive = archive;
149147
this.homeDirectory = getHomeDirectory();
150148
initializeProperties();
151-
this.paths = getPaths();
152149
this.classPathIndex = getClassPathIndex(this.archive);
153150
}
154151

@@ -295,7 +292,7 @@ private void addToSystemProperties() {
295292
private List<String> getPaths() throws Exception {
296293
String path = getProperty(PATH);
297294
List<String> paths = (path != null) ? parsePathsProperty(path) : Collections.emptyList();
298-
debug.log("Nested archive paths: %s", this.paths);
295+
debug.log("Nested archive paths: %s", paths);
299296
return paths;
300297
}
301298

loader/spring-boot-loader/src/test/java/org/springframework/boot/loader/launch/PropertiesLauncherTests.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ void testUserSpecifiedConfigName() throws Exception {
127127
System.setProperty("loader.config.name", "foo");
128128
this.launcher = new PropertiesLauncher();
129129
assertThat(this.launcher.getMainClass()).isEqualTo("my.Application");
130-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[etc/]");
130+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[etc/]");
131131
}
132132

133133
@Test
@@ -141,14 +141,14 @@ void testRootOfClasspathFirst() throws Exception {
141141
void testUserSpecifiedDotPath() throws Exception {
142142
System.setProperty("loader.path", ".");
143143
this.launcher = new PropertiesLauncher();
144-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[.]");
144+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[.]");
145145
}
146146

147147
@Test
148148
void testUserSpecifiedSlashPath() throws Exception {
149149
System.setProperty("loader.path", "jars/");
150150
this.launcher = new PropertiesLauncher();
151-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
151+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[jars/]");
152152
Set<URL> urls = this.launcher.getClassPathUrls();
153153
assertThat(urls).areExactly(1, endingWith("app.jar"));
154154
}
@@ -158,7 +158,7 @@ void testUserSpecifiedWildcardPath() throws Exception {
158158
System.setProperty("loader.path", "jars/*");
159159
System.setProperty("loader.main", "demo.Application");
160160
this.launcher = new PropertiesLauncher();
161-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/]");
161+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[jars/]");
162162
this.launcher.launch(new String[0]);
163163
waitFor("Hello World");
164164
}
@@ -168,7 +168,7 @@ void testUserSpecifiedJarPath() throws Exception {
168168
System.setProperty("loader.path", "jars/app.jar");
169169
System.setProperty("loader.main", "demo.Application");
170170
this.launcher = new PropertiesLauncher();
171-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
171+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[jars/app.jar]");
172172
this.launcher.launch(new String[0]);
173173
waitFor("Hello World");
174174
}
@@ -177,7 +177,7 @@ void testUserSpecifiedJarPath() throws Exception {
177177
void testUserSpecifiedRootOfJarPath() throws Exception {
178178
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/");
179179
this.launcher = new PropertiesLauncher();
180-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
180+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths"))
181181
.hasToString("[jar:file:./src/test/resources/nested-jars/app.jar!/]");
182182
Set<URL> urls = this.launcher.getClassPathUrls();
183183
assertThat(urls).areExactly(1, endingWith("foo.jar!/"));
@@ -216,7 +216,7 @@ void testUserSpecifiedNestedJarPath() throws Exception {
216216
System.setProperty("loader.path", "nested-jars/nested-jar-app.jar!/BOOT-INF/classes/");
217217
System.setProperty("loader.main", "demo.Application");
218218
this.launcher = new PropertiesLauncher();
219-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
219+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths"))
220220
.hasToString("[nested-jars/nested-jar-app.jar!/BOOT-INF/classes/]");
221221
this.launcher.launch(new String[0]);
222222
waitFor("Hello World");
@@ -236,7 +236,7 @@ void testUserSpecifiedJarPathWithDot() throws Exception {
236236
System.setProperty("loader.path", "./jars/app.jar");
237237
System.setProperty("loader.main", "demo.Application");
238238
this.launcher = new PropertiesLauncher();
239-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
239+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[jars/app.jar]");
240240
this.launcher.launch(new String[0]);
241241
waitFor("Hello World");
242242
}
@@ -246,7 +246,7 @@ void testUserSpecifiedClassLoader() throws Exception {
246246
System.setProperty("loader.path", "jars/app.jar");
247247
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
248248
this.launcher = new PropertiesLauncher();
249-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths")).hasToString("[jars/app.jar]");
249+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths")).hasToString("[jars/app.jar]");
250250
this.launcher.launch(new String[0]);
251251
waitFor("Hello World");
252252
}
@@ -256,7 +256,7 @@ void testUserSpecifiedClassPathOrder() throws Exception {
256256
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
257257
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
258258
this.launcher = new PropertiesLauncher();
259-
assertThat(ReflectionTestUtils.getField(this.launcher, "paths"))
259+
assertThat(ReflectionTestUtils.<Object>invokeMethod(this.launcher, "getPaths"))
260260
.hasToString("[more-jars/app.jar, jars/app.jar]");
261261
this.launcher.launch(new String[0]);
262262
waitFor("Hello Other World");
@@ -325,8 +325,8 @@ void testLoadPathCustomizedUsingManifest() throws Exception {
325325
manifest.write(manifestStream);
326326
}
327327
this.launcher = new PropertiesLauncher();
328-
assertThat((List<String>) ReflectionTestUtils.getField(this.launcher, "paths")).containsExactly("/foo.jar",
329-
"/bar/");
328+
assertThat((List<String>) ReflectionTestUtils.invokeMethod(this.launcher, "getPaths"))
329+
.containsExactly("/foo.jar", "/bar/");
330330
}
331331

332332
@Test

0 commit comments

Comments
 (0)