Skip to content

Fix matching against one of multiple env-variables pointing to one JDK#148

Open
HannesWell wants to merge 1 commit intoapache:masterfrom
HannesWell:fix-multi-env-variable-matching
Open

Fix matching against one of multiple env-variables pointing to one JDK#148
HannesWell wants to merge 1 commit intoapache:masterfrom
HannesWell:fix-multi-env-variable-matching

Conversation

@HannesWell
Copy link

The arguments when matching the collected env-variables pointing to one JDK against the required one were mistakenly swapped. This had the effect that the 'env'-variable match always failed when more than one env variable points to the same JDK.

This happens if in an environment multiple JDKs are available through structured environment variables (e.g. JAVA_17_HOME, JAVA_21_HOME, JAVA_25_HOME) and one of them is used as 'main' JDK and therefore JAVA_HOME also points to it.

As long as only one env variable points to a JDK, this error does not make a difference.

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 integration tests successfully (mvn -Prun-its verify).

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.

@HannesWell
Copy link
Author

@gnodet you have written that part, could you please have a look?
This can really make life difficult.

return RequirementMatcherFactory.createVersionMatcher(tcVal).matches(reqVal);
case ENV:
return reqVal.matches("(.*,|^)\\Q" + tcVal + "\\E(,.*|$)");
return tcVal.matches("(.*,|^)\\Q" + reqVal + "\\E(,.*|$)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a unit test will be appreciated for such code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I already wanted to add one.
But I found only one very basic test for this at all and setting up a complete new test infrastructure for this was a bit too much work for me at the moment. :/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a second look and maybe it's simpler than assumed. And I oversaw the IT tests.
But I assume a unit test would be possible relatively easy.
I'm looking into it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test will be enough, I'm fine to make method package protected and simply test it,
eg. we can provide many examples by parameterized test

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've now figured out how to setup an integration test (and handle the trickery of Windows path with back-slashes).

Setting up a unit test would probably also be possible with the adjustments you mentioned, but since the most relevant part of the logic is in the Mojo, would again need more non trivial test setup.

The arguments when matching the collected env-variables pointing to one
JDK against the required one were mistakenly swapped.
This had the effect that the 'env'-variable match always failed when
more than one env variable points to the same JDK.
@HannesWell HannesWell force-pushed the fix-multi-env-variable-matching branch from ce0b039 to 22768cc Compare March 11, 2026 19:04
@HannesWell
Copy link
Author

@slawekjaranowski can we proceed with this PR now that it also has integration tests?

@HannesWell
Copy link
Author

HannesWell commented Mar 17, 2026

Most of the workflows are canceled due to timeouts after a very short time and a successful build.
One build is fully successful and one build fails.
Can anyone help with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants