From 22d41d919adcab0626a66e8ecc162afe233afc7b Mon Sep 17 00:00:00 2001 From: Matthias Jaros Date: Wed, 19 Aug 2026 09:31:13 +0200 Subject: exitcode Variable needed because finally block does not run after exit Use System.exit only if return code is !=0 --- src/main/java/com/it_jaros/jns/App.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/it_jaros/jns/App.java b/src/main/java/com/it_jaros/jns/App.java index 166715d..7fb2415 100644 --- a/src/main/java/com/it_jaros/jns/App.java +++ b/src/main/java/com/it_jaros/jns/App.java @@ -13,17 +13,22 @@ public class App { private static final CountDownLatch shutdownLatch = new CountDownLatch(1); public static void main(String[] args) { + int exitCode = 0; try { run(args); } catch (HelpRequested e) { // Do nothing } catch (Exception e) { System.err.println(e.getMessage()); - System.exit(1); + exitCode = 1; } finally { shutdownLatch.countDown(); removeShutdownHook(); } + + if (exitCode != 0) { + System.exit(exitCode); + } } private static void run(String[] args) throws Exception { -- cgit v1.3.1