Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions e2e/cli/test_latest
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ assert "mise latest java | grep -E '^[0-9]+(\\.[0-9]+)*$'"
assert "mise latest java@temurin | grep -E '\\-[0-9]+(\\.[0-9]+)*(\..*)?$'"
# assert vendor 21 version ends with -21.N.N(-SUFFIX)?
assert "mise latest java@temurin-21 | grep -E '\\-21(\\.[0-9]+)*(\..*)?$'"
# assert base vendor preference (e.g. liberica instead of liberica-nik)
assert "mise latest java@liberica | grep -E 'liberica\\-[0-9]+(\\.[0-9]+)*(\..*)?$'"

# Python
# assert shorthand is a N.N.N version
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/core/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,12 @@ impl Backend for JavaPlugin {
.is_some_and(|image_type| image_type == "jdk"),
};
let features = 10 - m.features.as_ref().map_or(0, |f| f.len());
let version = Versioning::new(v);
let version = Versioning::new(&m.version);
// Extract build suffix after a '+', '.' if present. If not present, treat as 0.
let build_num = v
let build_num = m
.version
.rsplit_once('+')
.or_else(|| v.rsplit_once('.'))
.or_else(|| m.version.rsplit_once('.'))
Comment on lines +418 to +423

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Remove the fallback that splits on . for build_num extraction.

The .or_else(|| m.version.rsplit_once('.')) fallback can mistakenly extract the patch version as the build number for releases lacking build metadata (e.g., for 17.0.2, it extracts 2).

If Versioning ignores build metadata in precedence (per SemVer), this creates a sorting inversion where an older base release like 17.0.2 (incorrectly assigned build_num = 2) sorts higher than its own subsequent build like 17.0.2+1 (correctly assigned build_num = 1). Since Versioning natively handles dot-separated version segments (like 17.0.2.8), build_num is strictly only needed to break ties for + suffixes.

💡 Proposed fix
-                // Extract build suffix after a '+', '.' if present. If not present, treat as 0.
+                // Extract build suffix after a '+' if present. If not present, treat as 0.
                 let build_num = m
                     .version
                     .rsplit_once('+')
-                    .or_else(|| m.version.rsplit_once('.'))
                     .and_then(|(_, tail)| {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let version = Versioning::new(&m.version);
// Extract build suffix after a '+', '.' if present. If not present, treat as 0.
let build_num = v
let build_num = m
.version
.rsplit_once('+')
.or_else(|| v.rsplit_once('.'))
.or_else(|| m.version.rsplit_once('.'))
let version = Versioning::new(&m.version);
// Extract build suffix after a '+' if present. If not present, treat as 0.
let build_num = m
.version
.rsplit_once('+')
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/plugins/core/java.rs` around lines 418 - 423, Update build_num extraction
in the Versioning flow to use only the '+' suffix; remove the fallback that
splits on '.'. Preserve the default build number behavior when no '+' build
metadata exists, while allowing Versioning to handle dot-separated version
segments.

.and_then(|(_, tail)| {
// take leading digits of tail
let digits: String =
Expand All @@ -431,8 +432,12 @@ impl Backend for JavaPlugin {
}
})
.unwrap_or(0u64);
// Prefer base vendors (no dashes) over specialized variants like
// "liberica-nik". Fewer dashes → more canonical → sorts later.
let vendor_dashes = -(vendor.chars().filter(|c| *c == '-').count() as i32);
(
is_shorthand,
vendor_dashes,
vendor,
is_jdk,
features,
Expand Down