diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/commons/ParentProcessWatcher.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/commons/ParentProcessWatcher.java index 8919f788a2..ff27a3eca4 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/commons/ParentProcessWatcher.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/commons/ParentProcessWatcher.java @@ -28,6 +28,7 @@ public final class ParentProcessWatcher implements Runnable, Function{ private static final Logger LOGGER = Logger.getLogger(ParentProcessWatcher.class.getName()); + private static final boolean isJava1x = System.getProperty("java.version").startsWith("1."); /** * Exit code returned when XML Language Server is forced to exit. @@ -106,6 +107,28 @@ private boolean parentProcessStillRunning() { // On Windows, when the Java LS is idle, we need to explicitly request a GC, // to prevent an accumulation of zombie processes, as finalize() will be called. if (isWindows) { + // Java >= 9 doesn't close the handle when the process is garbage collected + // We need to close the opened streams + if (!isJava1x) { + try { + if (process.getInputStream() != null) { + process.getInputStream().close(); + } + } catch (IOException e) { + } + try { + if (process.getOutputStream() != null) { + process.getOutputStream().close(); + } + } catch (IOException e) { + } + try { + if (process.getErrorStream() != null) { + process.getErrorStream().close(); + } + } catch (IOException e) { + } + } System.gc(); } }