Skip to content

Make LookupContext#closeables thread safe#12411

Merged
gnodet merged 1 commit into
apache:masterfrom
oehme:master
Jul 3, 2026
Merged

Make LookupContext#closeables thread safe#12411
gnodet merged 1 commit into
apache:masterfrom
oehme:master

Conversation

@oehme

@oehme oehme commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This collection is modified by multiple threads, e.g. the FastTerminal setup thread calling context.closeables.add(out::flush). This can result in closeables being lost and can make subsequent builds with the embedded runner fail.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

This collection is modified by multiple threads, e.g. the FastTerminal
setup thread calling context.closeables.add(out::flush). This can result
in closeables being lost and can make subsequent builds with the embedded
runner fail.

Signed-off-by: Stefan Oehme <st.oehme@gmail.com>
@oehme

oehme commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

I found this while investigating the logging stackoverflows which we are still getting on a daily basis with Maven 4.x. I got a lucky break today and found a build where it didn't stackoverflow, but instead failed here:

Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 0
    at java.base/java.util.ArrayList.add(ArrayList.java:484)
    at java.base/java.util.ArrayList.add(ArrayList.java:496)
    at org.apache.maven.cling.invoker.LookupInvoker.doCreateTerminal(LookupInvoker.java:344)
    at org.apache.maven.cling.invoker.LookupInvoker.lambda$createTerminal$5(LookupInvoker.java:316)
    at org.apache.maven.jline.MessageUtils.lambda$systemInstall$0(MessageUtils.java:55)
    at org.apache.maven.jline.FastTerminal.lambda$new$0(FastTerminal.java:55)

I suspect this may be the cause for the stackoverflows, because with the right timing, the arraylist#add could succed and overwrite another closeable in the list.

@gnodet gnodet merged commit c48ad20 into apache:master Jul 3, 2026
22 checks passed
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

@gnodet Please assign appropriate label to PR according to the type of change.

@github-actions github-actions Bot added this to the 4.1.0 milestone Jul 3, 2026
@gnodet gnodet added the bug Something isn't working label Jul 3, 2026
gnodet added a commit that referenced this pull request Jul 3, 2026
This collection is modified by multiple threads, e.g. the FastTerminal
setup thread calling context.closeables.add(out::flush). This can result
in closeables being lost and can make subsequent builds with the embedded
runner fail.

Signed-off-by: Stefan Oehme <st.oehme@gmail.com>
Co-authored-by: Stefan Oehme <st.oehme@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants