{"record":{"id":"a7bb461bfd377c0b","repo":"elastic/elasticsearch","slug":"unknown-rest-api-version","errorCode":null,"errorMessage":"Unknown REST API version {}","messagePattern":"Unknown REST API version (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/core/src/main/java/org/elasticsearch/core/RestApiVersion.java","lineNumber":72,"sourceCode":"        };\n    }\n\n    public static Predicate<RestApiVersion> onOrAfter(RestApiVersion restApiVersion) {\n        return switch (restApiVersion) {\n            case V_9 -> r -> r.major >= V_9.major;\n            case V_8 -> r -> r.major >= V_8.major;\n        };\n    }\n\n    public static RestApiVersion forMajor(int major) {\n        switch (major) {\n            case 8 -> {\n                return V_8;\n            }\n            case 9 -> {\n                return V_9;\n            }\n            default -> throw new IllegalArgumentException(\"Unknown REST API version \" + major);\n        }\n    }\n}\n","sourceCodeStart":54,"sourceCodeEnd":76,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/core/src/main/java/org/elasticsearch/core/RestApiVersion.java#L54-L76","documentation":"Thrown by RestApiVersion.forMajor(int) when the requested major version is not one of the explicitly enumerated cases (8 or 9). RestApiVersion only models major REST API versions that Elasticsearch still supports, so any other major — older (<=7) or newer (>=10) in this build — is rejected. This is an API-contract guard, not a network-layer check.","triggerScenarios":"Calling RestApiVersion.forMajor(7), forMajor(10), forMajor(0), or any int outside {8,9} in this source tree. Common in serialization paths that read a major version byte from a stream or header and resolve it to the enum.","commonSituations":"Reading a versioned wire format or a Compatible-With header (Accept: application/vnd.elasticsearch+json;compatible=7) targeting a major this binary does not model. Cross-version cluster communication where one node is older/newer. A test using a stale major constant.","solutions":["Pin the major to 8 or 9, which are the supported versions in this build (see RestApiVersion enum).","If you must handle a broader range, branch on the int before calling forMajor and reject/handle unknown majors explicitly.","For compatibility tests against older majors, use the V_8 constant (minimumSupported) rather than a hard-coded 7.","Regenerate or update version constants if this code was ported from an older branch — the switch only knows current majors."],"exampleFix":"// before\nRestApiVersion v = RestApiVersion.forMajor(7); // throws\n\n// after\nRestApiVersion v = RestApiVersion.minimumSupported(); // V_8 in this build","handlingStrategy":"validation","validationCode":"// Validate a major before calling forMajor\nstatic RestApiVersion safeForMajor(int major) {\n    return switch (major) {\n        case 8 -> RestApiVersion.V_8;\n        case 9 -> RestApiVersion.V_9;\n        default -> throw new IllegalArgumentException(\"Unsupported REST API major \" + major);\n    };\n}","typeGuard":"static boolean isSupportedMajor(int major) {\n    return major == 8 || major == 9; // keep in sync with RestApiVersion enum\n}","tryCatchPattern":"try {\n    RestApiVersion v = RestApiVersion.forMajor(major);\n} catch (IllegalArgumentException e) {\n    // negotiate or reject the request; do not continue with an unknown version\n    throw new BadRequestException(\"Unsupported API version: \" + major);\n}","preventionTips":["Branch on the raw major int before resolving to the enum so unknowns are handled explicitly.","Use RestApiVersion.minimumSupported() / current() instead of hard-coded majors.","When reading a version from a wire format, validate against the enum's supported set.","Update version-aware code when bumping the supported major in RestApiVersion."],"tags":["rest-api","versioning","elasticsearch-core","compatibility","enum"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}