Uploaded image for project: 'Maven'
  1. Maven
  2. MNG-7161

Error thrown during uninstalling of JAnsi



    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 3.0-alpha-1, 3.8.2, 4.0.0
    • 3.8.2, 4.0.0-alpha-2, 4.0.0
    • None
    • None


      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:

        at org.fusesource.jansi.AnsiPrintStream.uninstall(AnsiPrintStream.java:79)
        at org.fusesource.jansi.AnsiConsole.systemUninstall(AnsiConsole.java:524)
        at org.apache.maven.shared.utils.logging.MessageUtils.doSystemUninstall(MessageUtils.java:101)
        at org.apache.maven.shared.utils.logging.MessageUtils.systemUninstall(MessageUtils.java:80)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:203)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)

      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?


        Issue Links



              michael-o Michael Osipov
              Brand Guy Brand
              0 Vote for this issue
              7 Start watching this issue