Skip to content

Commit cf4b068

Browse files
committed
fix: catch run exception in order to have a proper exit code.
1 parent 2e9c66b commit cf4b068

File tree

3 files changed

+20
-6
lines changed
  • spring-boot-project/spring-boot-tools
    • spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools
    • spring-boot-loader/src/main/java/org/springframework/boot/loader/launch
    • spring-boot-loader-classic/src/main/java/org/springframework/boot/loader/jarmode

3 files changed

+20
-6
lines changed

spring-boot-project/spring-boot-tools/spring-boot-jarmode-tools/src/main/java/org/springframework/boot/jarmode/tools/ExtractCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ private void checkJarCompatibility() throws IOException {
147147
try (ZipInputStream stream = new ZipInputStream(new FileInputStream(file))) {
148148
ZipEntry entry = stream.getNextEntry();
149149
if (entry == null) {
150-
System.err.printf("File '%s' is not compatible; ensure jar file is valid and launch script is not enabled%n", file);
151-
System.exit(1);
150+
throw new AbortException(
151+
"File '%s' is not compatible; ensure jar file is valid and launch script is not enabled"
152+
.formatted(file));
153+
152154
}
153155
}
154156
}

spring-boot-project/spring-boot-tools/spring-boot-loader-classic/src/main/java/org/springframework/boot/loader/jarmode/JarModeLauncher.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ public static void main(String[] args) {
4040
ClassUtils.getDefaultClassLoader());
4141
for (JarMode candidate : candidates) {
4242
if (candidate.accepts(mode)) {
43-
candidate.run(mode, args);
44-
return;
43+
try {
44+
candidate.run(mode, args);
45+
return;
46+
} catch (RuntimeException e) {
47+
if (!Boolean.getBoolean(DISABLE_SYSTEM_EXIT)) {
48+
System.exit(1);
49+
}
50+
}
4551
}
4652
}
4753
System.err.println("Unsupported jarmode '" + mode + "'");

spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/launch/JarModeRunner.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ static void main(String[] args) {
4040
ClassUtils.getDefaultClassLoader());
4141
for (JarMode candidate : candidates) {
4242
if (candidate.accepts(mode)) {
43-
candidate.run(mode, args);
44-
return;
43+
try {
44+
candidate.run(mode, args);
45+
return;
46+
} catch (RuntimeException e) {
47+
if (!Boolean.getBoolean(DISABLE_SYSTEM_EXIT)) {
48+
System.exit(1);
49+
}
50+
}
4551
}
4652
}
4753
System.err.println("Unsupported jarmode '" + mode + "'");

0 commit comments

Comments
 (0)