As per JDK-8371944, some application may close System.out (usually inadvertently by naive code like the following):
try (var err = new PrintWriter(System.err);
var out = new PrintWriter(System.out)) {
out.println("Hello Confused World");
}
This has the side effect of closing the JVM's stdout/stderr. On Windows we access the output device via a HANDLE which is an opaque 64-bit integer value. When System.out/err is closed by the Java code, the HANDLE value becomes available for re-use - e.g for a file. If that happens then the VM's use of stdout/stderr will go to that file. On non-Windows file descriptors 1 and 2 never get re-assigned so no similar problem occurs there (though the VM will still try writing to a closed fd).
Whilst this is likely "day one" behaviour it seems not to have been clearly reported as a bug - likely due to the low probability of closing System.out/err and the even lower probability that the handle gets re-assigned to a newly opened file.
try (var err = new PrintWriter(System.err);
var out = new PrintWriter(System.out)) {
out.println("Hello Confused World");
}
This has the side effect of closing the JVM's stdout/stderr. On Windows we access the output device via a HANDLE which is an opaque 64-bit integer value. When System.out/err is closed by the Java code, the HANDLE value becomes available for re-use - e.g for a file. If that happens then the VM's use of stdout/stderr will go to that file. On non-Windows file descriptors 1 and 2 never get re-assigned so no similar problem occurs there (though the VM will still try writing to a closed fd).
Whilst this is likely "day one" behaviour it seems not to have been clearly reported as a bug - likely due to the low probability of closing System.out/err and the even lower probability that the handle gets re-assigned to a newly opened file.
- relates to
-
JDK-8371944 AOT configuration is corrupted when app closes System.out
-
- Resolved
-