{"id":"119d8abb85077204","repo":"apache/kafka","slug":"unknown-isolation-level-id","errorCode":null,"errorMessage":"Unknown isolation level \" + id","messagePattern":"Unknown isolation level \" \\+ id","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/IsolationLevel.java","lineNumber":45,"sourceCode":"\n    private final byte id;\n\n    IsolationLevel(byte id) {\n        this.id = id;\n    }\n\n    public byte id() {\n        return id;\n    }\n\n    public static IsolationLevel forId(byte id) {\n        switch (id) {\n            case 0:\n                return READ_UNCOMMITTED;\n            case 1:\n                return READ_COMMITTED;\n            default:\n                throw new IllegalArgumentException(\"Unknown isolation level \" + id);\n        }\n    }\n\n    @Override\n    public String toString() {\n        return super.toString().toLowerCase(Locale.ROOT);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":54,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/IsolationLevel.java#L27-L54","documentation":"Thrown by IsolationLevel.forId(byte) when a caller (typically request/response deserialization) asks for the IsolationLevel matching a byte id that is neither 0 (READ_UNCOMMITTED) nor 1 (READ_COMMITTED). The message is built by string concatenation (\"Unknown isolation level \" + id) so the offending numeric id appears in the text. It indicates an unexpected isolation level code on the wire, almost always a version mismatch or a malformed/mock payload rather than user config (users set isolation.level by name).","triggerScenarios":"Deserialization of a FetchRequest/FetchResponse or ListOffsets request whose isolation_level field is outside {0,1}; a broker-client version skew where one side sends a value the other enum doesn't recognize; hand-crafted protocol bytes in tests; a proxy/middleware rewriting the field incorrectly.","commonSituations":"Mixing client and broker versions across an unsupported range; using a non-Apache Kafka broker or proxy that emits a non-standard isolation level code; mocks/fuzz tests that fabricate FetchRequest data; misbehaving SDK fork that added an enum value not understood by standard clients.","solutions":["Align client and broker versions to a supported combination; check broker and client release notes for isolation-level protocol changes.","If using a proxy/SDK fork, verify it only emits isolation level 0 or 1 on the wire.","When constructing requests programmatically, use IsolationLevel.READ_COMMITTED/READ_UNCOMMITTED constants (or the isolation.level config) instead of raw bytes.","For test fixtures, source the byte from IsolationLevel.forId/id() rather than hardcoding."],"exampleFix":"// before\nIsolationLevel lvl = IsolationLevel.forId((byte) 7);  // throws 298\n\n// after\nIsolationLevel lvl = IsolationLevel.READ_COMMITTED;  // id == 1\nbyte wire = lvl.id();  // safe to serialize","handlingStrategy":"validation","validationCode":"// Validate the byte id before calling IsolationLevel.forId:\nbyte candidate = id;\nif (candidate != 0 && candidate != 1) {\n    throw new IllegalArgumentException(\"Invalid isolation level id: \" + candidate\n        + \"; must be 0 (READ_UNCOMMITTED) or 1 (READ_COMMITTED)\");\n}\nIsolationLevel level = IsolationLevel.forId(candidate);","typeGuard":"import org.apache.kafka.common.IsolationLevel;\n\npublic static boolean isValidIsolationLevel(byte id) {\n    return id == IsolationLevel.READ_UNCOMMITTED.id() || id == IsolationLevel.READ_COMMITTED.id();\n}\n\npublic static java.util.Optional<IsolationLevel> safeIsolationLevel(byte id) {\n    return isValidIsolationLevel(id)\n        ? java.util.Optional.of(IsolationLevel.forId(id))\n        : java.util.Optional.empty();\n}","tryCatchPattern":"try {\n    IsolationLevel level = IsolationLevel.forId(id);\n} catch (IllegalArgumentException e) {\n    // Default defensively or reject; isolation levels are not something to guess at.\n    throw new IllegalArgumentException(\"Unsupported isolation level id \" + id\n        + \"; only 0 (READ_UNCOMMITTED) and 1 (READ_COMMITTED) are valid\", e);\n}","preventionTips":["Do not persist isolation levels as raw bytes without schema validation; serialize the name instead.","At every external boundary (config files, wire protocols, user input) restrict to the two known values.","Prefer IsolationLevel.valueOf(String) from a controlled name list, or hard-code to READ_COMMITTED for consumers unless you have a specific reason."],"tags":["consumer","protocol","enum","deserialization"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}