elharo opened a new pull request, #12629:
URL: https://github.com/apache/maven/pull/12629
Fixes #12607
## Problem
In `DefaultMaven.doExecute()`, `sessionScope.enter()` was called **outside**
the try-finally block:
```java
sessionScope.enter();
MavenChainedWorkspaceReader chainedWorkspaceReader =
new MavenChainedWorkspaceReader(request.getWorkspaceReader(),
ideWorkspaceReader);
try (CloseableSession closeableSession = ...) {
...
} finally {
sessionScope.exit();
}
```
If `new MavenChainedWorkspaceReader(...)` threw (it can throw an NPE if a
`WorkspaceReader`'s `getRepository()` returns `null`), the
`sessionScope.exit()` in the finally block would never execute. This leaked the
session scope's thread-local state.
## Fix
Wrapped `sessionScope.enter()` and all subsequent code in an outer
try-finally, ensuring `sessionScope.exit()` is always called regardless of
where the exception occurs.
## Testing
Added `DefaultMavenSessionScopeTest` which:
1. Creates a mock `WorkspaceReader` whose `getRepository()` returns `null`
(triggering NPE in `MavenChainedWorkspaceReader`)
2. Calls `DefaultMaven.execute()` with this bad reader
3. Verifies the session scope is properly exited (empty internal values
list) even though the request failed
--
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]