void () { String output = null; try { Runnable shutdownHook = () -> { }; try { output = "foo"; } finally { Runtime.getRuntime().addShutdownHook(new Thread(shutdownHook)); shutdownHook.run(); } } finally { System.out.println(<warning descr="Condition 'output != null' is always 'true'">output != null</warning> ? output.trim() : ""); } System.out.println(output.trim()); }