Commit 653da37
fix: make JDK.min(Set, String) actually use the jdks parameter (#1713)
* fix: make JDK.min(Set, String) actually use the jdks parameter
The previous implementation had a precedence bug:
if (jdks == null || jdks.isEmpty() && jenkinsVersion == null)
Because && binds tighter than ||, this evaluated as:
if (jdks == null || (jdks.isEmpty() && jenkinsVersion == null))
As a result, whenever jdks was non-null and non-empty the method fell
through to a single-line return that completely ignored the jdks
argument. A plugin declaring e.g. [JAVA_17, JAVA_21] would get back
JAVA_11 for Jenkins 2.479.3, even though 11 is not in the declared set.
The fix rewrites the method to:
1. Fast-path on null jenkinsVersion (delegate to single-arg min).
2. Compute the version-range list once.
3. Intersect the caller-supplied jdks with that list and return the
minimum; fall back to the range minimum only when the intersection
is empty.
Also replaces the bare orElseThrow() with orElse(JDK.min()) to avoid
a cryptic NoSuchElementException when a future version boundary leaves
the supported list empty.
* fix: apply Spotless formatting to JDK.java
* fix: address Copilot review feedback on JDK.min(Set, String)
- Treat empty jenkinsVersion as absent (consistent with get(String))
- Return min(jdks) on no-intersection fallback instead of version-min
- Add tests for empty version string and no-overlap cases
- Clarify Javadoc to document no-intersection fallback behavior
---------
Co-authored-by: Valentin Delaye <jonesbusy@users.noreply.github.com>1 parent 6459213 commit 653da37
2 files changed
Lines changed: 34 additions & 6 deletions
File tree
- plugin-modernizer-core/src
- main/java/io/jenkins/tools/pluginmodernizer/core/model
- test/java/io/jenkins/tools/pluginmodernizer/core/model
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
263 | | - | |
264 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
265 | 269 | | |
266 | 270 | | |
267 | | - | |
268 | | - | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
269 | 277 | | |
270 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
271 | 283 | | |
272 | 284 | | |
273 | 285 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
68 | 84 | | |
69 | 85 | | |
70 | 86 | | |
| |||
0 commit comments