{"record":{"id":"fa0c25a4b831d91f","repo":"oracle/graal","slug":"cannot-compare-javalangruntimeversion-name-t","errorCode":null,"errorMessage":"Cannot compare {JavaLangRuntimeVersion.__name__} to {type(other).__name__}","messagePattern":"Cannot compare (.+?) to (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"compiler/mx.compiler/mx_compiler.py","lineNumber":97,"sourceCode":"jdk = mx.get_jdk(tag='default')\n\n\nclass JavaLangRuntimeVersion(mx.Comparable):\n    \"\"\"Wrapper for java.lang.Runtime.Version\"\"\"\n\n    _cmp_cache = {}\n    _feature_re = re.compile('[1-9][0-9]*')\n\n    def __init__(self, version, jdk=None):\n        self.version = version\n        self.jdk = jdk or mx.get_jdk()\n\n    def __str__(self):\n        return self.version\n\n    def __cmp__(self, other):\n        if not isinstance(other, JavaLangRuntimeVersion):\n            raise TypeError(f'Cannot compare {JavaLangRuntimeVersion.__name__} to {type(other).__name__}')\n        this_version = self.version\n        other_version = other.version\n        if this_version == other_version:\n            return 0\n        if self.feature() == 21 and other.feature() == 21:\n            # JDK 21 uses the legacy version scheme where the jdkVersion is irrelevant (and imprecise).\n            # Thus, we do not perform a full version check.\n            return 0\n        return JavaLangRuntimeVersion.compare(this_version, other_version, jdk)\n\n    @staticmethod\n    def compare(this_version, other_version, jdk):\n        key = (this_version, other_version)\n        cached = JavaLangRuntimeVersion._cmp_cache.get(key, None)\n        if cached is not None:\n            return cached\n        source_path = join(_suite.dir, 'src', 'jdk.graal.compiler', 'src', 'jdk', 'graal', 'compiler',\n                           'hotspot',","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/mx.compiler/mx_compiler.py#L79-L115","documentation":"Thrown by Version.create(int...) when any component of the version string, after trailing zeros are trimmed, is less than zero. The factory validates that a version is built from at least one non-zero, non-negative integer component before constructing the immutable Version. It is an IllegalArgumentException, so it signals caller misuse of the varargs API rather than an environment problem.","triggerScenarios":"Calling Version.create(-1, 0, 0), Version.create(19, -3), or passing an array containing a negative element (e.g. parsed from user input like \"19.-3.0\"). Note trailing zeros are trimmed first, so Version.create(0) fails earlier with 'At least one non-zero version must be specified.' instead.","commonSituations":"Parsing version numbers from CLI arguments, config files, or manifest data without sanitizing; arithmetic that computes a version component and can go negative (e.g. decrementing a minor version past 0); unit tests exercising malformed version input.","solutions":["Validate all components are >= 0 (and at least one > 0) before calling Version.create.","If the value comes from a string, parse with a strict pattern such as \\d+(\\.\\d+)* so negatives can never reach the API.","Clamp or reject negative computed components at the source (the calculation that produced them) instead of catching the exception."],"exampleFix":"// before\nVersion v = Version.create(major, minor - 1, patch);\n\n// after\nif (minor - 1 < 0) {\n    throw new IllegalArgumentException(\"minor version would go negative: \" + minor);\n}\nVersion v = Version.create(major, minor - 1, patch);","handlingStrategy":"validation","validationCode":"static boolean isValidVersion(int... parts) {\n    boolean anyNonZero = false;\n    for (int p : parts) {\n        if (p < 0) return false;\n        if (p != 0) anyNonZero = true;\n    }\n    return anyNonZero;\n}\n\n// before calling:\nif (!isValidVersion(major, minor, patch)) throw new IllegalArgumentException(\"bad version parts\");\nVersion.create(major, minor, patch);","typeGuard":null,"tryCatchPattern":"try {\n    Version v = Version.create(parts);\n} catch (IllegalArgumentException e) {\n    // surface as config-validation error to the user; do not retry\n}","preventionTips":["Parse versions from strings with a strict ^\\d+(\\.\\d+)*$ regex so negatives never reach create().","Validate integer inputs (>= 0, at least one > 0) at the API boundary where they enter your code."],"tags":["version","validation","illegal-argument","graalvm-sdk"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}