Dev-next-gen opened a new pull request, #13152:
URL: https://github.com/apache/maven/pull/13152
I was comparing the Maven 3 profile activators in
`compat/maven-model-builder` with their Maven 4 counterparts in
`impl/maven-impl` and found one line that did not come across:
`OperatingSystemProfileActivator.determineFamilyMatch` lower-cases the
configured family in the Maven 3 copy, but not in the Maven 4 one.
The Maven 3 side got that in 0456c7c62 ("Caplital OS name can not activate
profile"), which lower-cased `name`, `arch` and `family` together. The Maven 4
activator introduced in d075fe7e85 was written from the state before that
commit; `name` and `arch` were later brought in line, `family` was not.
It matters because `Os.isFamily` switches on the family string against
lower-case constants — `"windows"`, `"winnt"`, `"win9x"`, `"unix"`, `"dos"`,
`"mac"`, `"tandem"`, and so on — and only the `default` branch does
`actualOsName.contains(family.toLowerCase(...))`. So a capitalised family never
reaches its own case and silently degrades into a substring test on `os.name`.
Some families survive that by luck, because their name is a substring of the OS
name: `<family>Mac</family>` still matches `mac os x`, which is exactly the
case the existing `testCapitalOsName` covers, so the test passes while the code
is wrong. The families that actually need the switch do not survive it:
- `<family>WinNT</family>` does not activate on Windows — `"windows 11"`
does not contain `"winnt"`.
- `<family>Mac</family>` does not activate on a JDK that reports
`os.name=darwin`, which is the case the `DARWIN` constant in `Os` exists for.
- `<family>Unix</family>`, `<family>DOS</family>` and
`<family>Tandem</family>` are wrong the same way, and a negated form such as
`<family>!Unix</family>` flips the wrong way, i.e. it activates a profile that
was written to be excluded.
Same POM, activates under Maven 3, does not under Maven 4.
The change is the single `toLowerCase(Locale.ENGLISH)` call, so the family
follows the same rule as `name`, `arch` and `version` in the same class.
`Locale` is already imported.
The new `testCapitalFamily` fails before the change and passes after:
```
[ERROR] OperatingSystemProfileActivatorTest.testCapitalFamily:153
->AbstractProfileActivatorTest.assertActivation:77 expected: <true>
but was: <false>
[ERROR] Tests run: 11, Failures: 1, Errors: 0, Skipped: 0
```
and with the one-line change applied:
```
[INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
```
I avoided `<family>Unix</family>` in the test on purpose: the `unix` branch
of `Os.isFamily` reads `File.pathSeparator` of the running JVM, so it would
assert different things on the Linux and Windows CI runners. `winnt` and the
darwin case depend only on the `os.name` the test feeds in.
The whole `impl/maven-impl` suite is green with the change (703 tests, 0
failures, JDK 21). I have not run the Core ITs.
- [x] Your pull request should address just one issue, without pulling in
other changes.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied.
- [ ] Run `mvn verify` to make sure basic checks pass.
- [ ] You have run the [Core IT][core-its] successfully.
- [ ] I hereby declare this contribution to be licenced under the [Apache
License Version 2.0, January 2004](http://www.apache.org/licenses/LICENSE-2.0)
[core-its]: https://maven.apache.org/core-its/core-it-suite/
Found by a defect-hunting pipeline I build and run
([Dev-next-gen](https://github.com/Dev-next-gen)), using Claude Code with
Anthropic's Claude Opus 5.
--
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]