apache / apache/maven-surefire

Printing to the Standard Output Doesn’t Work from a JVM Shutdown Hook

Open
#849 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

### Affected version

3.5.3

### Bug description

Hi,
I have this simple JVM shutdown hook,

```
public class JVMShutdownHook {

static {
Thread hook = new Thread(() -> {
System.out.println("***********************Sysout from JVMShutdownHook***********************");
});
System.out.println("Register JVM Hook");
Runtime.getRuntime().addShutdownHook(hook);
}
}
```
It's registered in the `@BeforeAll` method

```
public class JVMHookApplicationTests {

@BeforeAll
public static final void initiateJVMHook() throws ClassNotFoundException {
Class.forName("com.example.jvmHook.JVMShutdownHook");
}

@Test
public void simpleTest() {
assertEquals(6, 6);
}
}
```
The `sysout` from the JVM hook doesn't work if the `forkCount `is greater than 0. The JVM hook gets called consistently, but printing to the standard output doesn't always work (it works sometimes, but the behaviour is inconsistent).

The problem started from Suefire version 3.0.0-M5. It works fine with 3.0.0-M4 and prior versions.

Here is a simple application showing this problem - https://github.com/asif-anwar/jvm-hook

Contributor guide

Open the contributing guide

Research direction

Start with the JVMShutdownHook and JVMHookApplicationTests examples in the issue, then reproduce the inconsistent output with forkCount greater than 0 using the linked application. Compare Surefire 3.0.0-M4 with 3.0.0-M5 and trace shutdown-hook output handling; done means the hook's standard output is reliably captured.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.