Our integration tests stopped working after we started to test with a Maven 4.0.0-alpha-1 nightly which included this commit: https://github.com/apache/maven/commit/195fb626a9a4e5a0774f779b6d8da1cb9ef38468#diff-9c5fb3d1b7e3b0f54bc5c4182965c4fe1f9023d449017cece3005d3f90e8e4d8R310-R317
In this commit the maven-shared-utils and the jansi dependencies are being upgraded. When we then run our integration tests we get the following null pointer exception:
We debugged this and these changes in JAnsi introduced in the above upgraded version, is the source of the exception. The NPE is caused because the out reference is null at the time it wants to uninstall the AnsiOutputStream. This reference is nulled because we use the Plexus interactivity library which disposes the DefaultOutputHandler on the tear down of Plexus, in which the System.out reference will be closed which is in fact the out reference of the AnsiConsole JAnsi will be initialized before the Plexus container). This happens here, so before JAnsi will be uninstalled in here.
There are two options to solve this:
1. Report this to JAnsi such that they catch this valid use case and do not throw as this worked without any exceptions in older versions.
2. Fix the MessageUtils#doSystemUninstall() and catch all exceptions and swallow them, as if it can't uninstall it, then Maven itself is not capable of fixing this state either. This is already done in a similar way here for removing the shutdown hook.
Our proposal is to do #2 which would make Maven itself resilient to such use cases as there are other extensions/plugin out there which also retrieve a reference for the system output streams and therefore they would fail with Maven 4.0.0. This would also make this part future proof, as when there are other errors thrown during the uninstall, Maven itself does not break.
We can as well report this to JAnsi too such that this gets fixed there as well.
What are your opinions on that?