gnodet opened a new pull request, #13193:
URL: https://github.com/apache/maven/pull/13193
## Summary
When `mvnup` processes a project whose `maven.compiler.release` (or
`source`) is **≥ 8** and the running JDK is older than that source level, it
incorrectly generates the invalid version constraint `(,-1]` in the toolchains
plugin configuration, causing a toolchain resolution failure at build time.
## Root Cause
`ToolchainPluginStrategy.doApply()` calls:
```java
int latestJdk = JdkSourceLevelSupport.latestJdkForSourceLevel(sourceLevel);
addToolchainsPlugin(pomDocument, latestJdk);
```
`latestJdkForSourceLevel()` returns `-1` for source levels 8+ (meaning
"still supported by all current JDKs — not retired"). This `-1` was passed
directly to `addToolchainsPlugin()`, which inserts it into the version range
string, producing:
```xml
<version>(,-1]</version>
```
This triggers:
```
[ERROR] Cannot find matching toolchain definitions for the following
toolchain types:{version=(,-1]}
```
**When does this path trigger?** `supportsSourceLevel(runningJdk,
sourceLevel)` returns `false` when `sourceLevel > runningJdk` — for example,
running JDK 17 with `maven.compiler.release=21`. The toolchain injection path
is reached, but `latestJdkForSourceLevel(21)` returns `-1`.
## Fix
Guard against `latestJdk <= 0` before calling `addToolchainsPlugin()`. When
`latestJdk <= 0`, the source level is valid for all current JDKs — the running
JDK is simply too old for the project's target level. Toolchain injection
cannot help (there is no older JDK that supports `--source 21`). Instead, emit
a warning explaining that the running JDK needs to be upgraded.
## Test
Added `noToolchainInjectionWhenSourceLevelTooNew` to
`ToolchainPluginStrategyTest`:
- Simulates running JDK 17, project with `maven.compiler.release=21`
- Asserts that the POM is **not** modified
- Asserts that the invalid string `(,-1]` never appears in the output
## Related
Fixes #13189. Observed in the `netbeans-html4j` compat test run
(gnodet/maven4-testing#39661).
---
_Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_
--
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]