arturobernalg opened a new pull request, #13760:
URL: https://github.com/apache/maven/pull/13760
Maven installs a `LoggingPrintStream` as `System.out`/`System.err`
(`LookupInvoker`) and registers a shutdown closeable that calls
`LoggingOutputStream.forceFlush(ps)` on it. That static helper guards with
`instanceof LoggingPrintStream`, but the instance method it then calls,
`LoggingPrintStream.forceFlush()`, casts its inherited `out` field
unconditionally:
```java
public void forceFlush() {
((LoggingOutputStream) out).forceFlush();
}
```
`PrintStream#close()` sets `out` to null. If anything closes
`System.out`/`System.err` itself before the shutdown hook runs -- for example a
build tool like Spotless's `spotlessIdeHook` -- `forceFlush()` then throws
`NullPointerException: Cannot invoke
"org.apache.maven.logging.LoggingOutputStream.forceFlush()" because "this.out"
is null`. This is what's reported in
https://github.com/apache/maven-mvnd/issues/1271; the bug is in maven-core,
mvnd just surfaces it (one commenter confirms it reproduces on plain Maven
4.0.0-rc-3-SNAPSHOT too).
Fix mirrors the same `instanceof` guard the static helper already uses, so a
closed/non-`LoggingOutputStream` target is a no-op instead of an NPE.
Added `LoggingOutputStreamTest` with a test that reproduces the NPE pre-fix
(closes the stream, then calls `forceFlush()`) and a second test confirming the
normal flush-before-close path still works. Full `maven-core` suite, checkstyle
and spotless pass locally.
---
To make clear that you license your contribution under
the [Apache License Version 2.0, January
2004](https://www.apache.org/licenses/LICENSE-2.0)
check one of the following:
- [x] I hereby declare this contribution to be licensed under the [Apache
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
- [x] I hereby declare that I have filed an [Apache Individual Contributor
License Agreement](https://www.apache.org/licenses/icla.pdf).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]