HMCL-dev/HMCL · error · IllegalArgumentException
Empty old version number
Error message
Empty old version number
What it means
GameVersionNumber.Old.parse throws IllegalArgumentException with the message 'Empty old version number' when asked to parse a legacy (pre-classic/alpha/beta) version identifier that is an empty string. The parser requires at least a type prefix character plus a digit, so empty input is rejected explicitly before the switch.
Solutions
- Validate the version string is non-empty before calling the parser and substitute a sensible default (e.g. skip comparison or use Release.ZERO)
- Fix the source data so the version id is populated
- Wrap parsing in try-catch for IllegalArgumentException and treat empty as unknown version
Example fix
// before
GameVersionNumber v = GameVersionNumber.asGameVersion(config.version);
// after
if (config.version == null || config.version.isEmpty()) {
return; // or use a default version
}
GameVersionNumber v = GameVersionNumber.asGameVersion(config.version); Defensive patterns
Strategy: validation
Validate before calling
static boolean isValidOldVersion(String v) {
return v != null && !v.isEmpty();
}
Try / catch
try {
GameVersionNumber v = GameVersionNumber.asGameVersion(raw);
} catch (IllegalArgumentException e) {
log.warn("Invalid version '{}': {}", raw, e.getMessage());
} Prevention
- Never pass version fields straight from config/JSON without a null/empty check
- Default missing version ids to a known placeholder or skip the comparison
- Validate upstream data sources for blank version entries
When it happens
Trigger: Passing "" to GameVersionNumber parsing (e.g. via GameVersionNumber.asGameVersion or comparison helpers) when the version string came from an empty version field in a version.json, a missing manifest entry, or an unfilled config value.
Common situations: Custom version JSON with an empty id; profile/config data missing a version field; upstream version lists containing blank entries.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10).
Data as JSON: /api/errors/b4248cbffcd2e735.
Report an issue: GitHub.
Appendix: source
Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/versioning/GameVersionNumber.java:234
if (gameVersion instanceof LegacySnapshot snapshot) {
String[] defaultVersions = Versions.DEFAULT_GAME_VERSIONS;
for (int i = defaultVersions.length - 1; i >= 0; i--) {
Release gaRelease = (Release) asGameVersion(defaultVersions[i]);
if (gaRelease.compareToSnapshot(snapshot) > 0) {
return gaRelease;
}
}
}
return null;
}
public static final class Old extends GameVersionNumber {
static Old parse(String value) {
if (value.isEmpty())
throw new IllegalArgumentException("Empty old version number");
Type type;
int prefixLength = 1;
switch (value.charAt(0)) {
case 'r':
if (!value.startsWith("rd-")) {
throw new IllegalArgumentException(value);
}
type = Type.PRE_CLASSIC;
prefixLength = "rd-".length();
break;
case 'i':
if (value.startsWith("inf-")) {
type = Type.INFDEV;
prefixLength = "inf-".length();
} else if (value.startsWith("in-")) {
type = Type.INDEV;View on GitHub (pinned to 24702dc5a0)