private void diagnoseFailedLoad(Exception cause) { Process proc = process.getProcess(); try { int val = proc.exitValue(); new RuntimeException("Jenkins died loading. Exit code " + val, cause); } catch (IllegalThreadStateException _) { // Process alive } // Try to get stacktrace Class<?> clazz; Field pidField; try { clazz = Class.forName("java.lang.UNIXProcess"); pidField = clazz.getDeclaredField("pid"); pidField.setAccessible(true); } catch (Exception e) { LinkageError x = new LinkageError(); x.initCause(e); throw x; } if (clazz.isAssignableFrom(proc.getClass())) { int pid; try { pid = (int) pidField.get(proc); } catch (IllegalArgumentException | IllegalAccessException e) { throw new AssertionError(e); } try { Process jstack = new ProcessBuilder("jstack", String.valueOf(pid)).start(); if (jstack.waitFor() == 0) { StringWriter writer = new StringWriter(); IOUtils.copy(jstack.getInputStream(), writer); RuntimeException ex = new RuntimeException( cause.getMessage() + "\n\n" + writer.toString() ); ex.setStackTrace(cause.getStackTrace()); throw ex; } } catch (IOException | InterruptedException e) { throw new AssertionError(e); } } throw new Error(cause); }