maven-mvnd icon indicating copy to clipboard operation
maven-mvnd copied to clipboard

Cannot invoke "org.apache.maven.logging.LoggingOutputStream.forceFlush()" because "this.out" is null

Open SapiensAnatis opened this issue 10 months ago • 2 comments

I'm running into a strange issue with spotless where mvnd is throwing what looks like an NPE after the goal completes:

$ mvnd spotless:apply -DspotlessIdeHook=/home/jay/Projects/mvnd-npe-repro/src/main/java/com/mycompany/app/App.java  
[INFO] Processing build on daemon 280ce708
[INFO] Scanning for projects...
[INFO] BuildTimeEventSpy is registered.
[INFO] 
[INFO] Using the SmartBuilder implementation with a thread count of 15
[INFO] 
[INFO] -----------------------------------------------< com.mycompany.app:my-app >-----------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] ---------------------------------------------------------[ jar ]----------------------------------------------------------
[INFO] 
[INFO] --- spotless:2.44.2:apply (default-cli) @ my-app ---
[INFO] Index file does not exist. Fallback to an empty index
[WARNING] [stderr] IS CLEAN
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------------------------------------------------------------------
[INFO] Total time:  0.193 s (Wall Clock)
[INFO] Finished at: 2025-02-14T21:28:56Z
[INFO] --------------------------------------------------------------------------------------------------------------------------
[ERROR] Error executing Maven Daemon.
[ERROR] Cannot invoke "org.apache.maven.logging.LoggingOutputStream.forceFlush()" because "this.out" is null

I've put together a minimal-ish repro here: https://github.com/SapiensAnatis/mvnd-npe-repro. It'll download Spotless as I wasn't confident I'd be able to work out exactly what Spotless is doing to trigger this and recreate it with a custom goal, so it's not truly minimal, but I hope it's a good start.

The file is formatted as expected so it looks to be an error during cleanup. If I remove the -DspotlessIdeHook flag, I don't get the NPE anymore.

This happens in 1.0.2, and I also built the latest commit from master where it still reproduces.

It does not reproduce on regular mvn (3.9.9) if I substitute that in the command above.

SapiensAnatis avatar Feb 14 '25 21:02 SapiensAnatis

The -DspotlessIdeHook will be going into here instead of the normal execution path, so perhaps something this code is doing is the cause of the problem:

https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/java/com/diffplug/spotless/maven/IdeHook.java

SapiensAnatis avatar Feb 14 '25 21:02 SapiensAnatis

Was just doing some more testing and it repros on normal mvn 4.0.0-rc-3-SNAPSHOT... perhaps this issue should be moved then

SapiensAnatis avatar Feb 14 '25 21:02 SapiensAnatis