{"record":{"id":"6d6fdd48a793ec15","repo":"TooTallNate/Java-WebSocket","slug":"don-t-know-how-to-handle-opcode","errorCode":null,"errorMessage":"Don't know how to handle {opcode}","messagePattern":"Don't know how to handle (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft_6455.java","lineNumber":868,"sourceCode":"    return buffer;\n  }\n\n\n  private byte fromOpcode(Opcode opcode) {\n    if (opcode == Opcode.CONTINUOUS) {\n      return 0;\n    } else if (opcode == Opcode.TEXT) {\n      return 1;\n    } else if (opcode == Opcode.BINARY) {\n      return 2;\n    } else if (opcode == Opcode.CLOSING) {\n      return 8;\n    } else if (opcode == Opcode.PING) {\n      return 9;\n    } else if (opcode == Opcode.PONG) {\n      return 10;\n    }\n    throw new IllegalArgumentException(\"Don't know how to handle \" + opcode.toString());\n  }\n\n  private Opcode toOpcode(byte opcode) throws InvalidFrameException {\n    switch (opcode) {\n      case 0:\n        return Opcode.CONTINUOUS;\n      case 1:\n        return Opcode.TEXT;\n      case 2:\n        return Opcode.BINARY;\n      // 3-7 are not yet defined\n      case 8:\n        return Opcode.CLOSING;\n      case 9:\n        return Opcode.PING;\n      case 10:\n        return Opcode.PONG;\n      // 11-15 are not yet defined","sourceCodeStart":850,"sourceCodeEnd":886,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft_6455.java#L850-L886","documentation":"Draft_6455's opcode-to-numeric mapping throws IllegalArgumentException(\"Don't know how to handle <opcode>\") when converting an Opcode enum value that has no numeric mapping (valid values are 0-10). This happens only with an internal/unknown Opcode, typically CONTINUOUS-with-FIN edge usage or a future opcode not covered by the if-chain.","triggerScenarios":"Calling the private numeric conversion (used when building outgoing frame headers) with an Opcode outside CONTINUOUS(0), TEXT(1), BINARY(2), CLOSE(8), PING(9), PONG(10) — e.g. a custom or newer Opcode enum member.","commonSituations":"Library version mismatch where custom code constructs frames with an Opcode the 6455 draft mapping does not know; passing frame objects built by another draft implementation; internal bugs.","solutions":["Only send frames using the draft's createFrames API instead of hand-building Framedata with raw opcodes","Upgrade Java-WebSocket so Opcode enum and Draft_6455 mapping are from the same version","Audit custom subclasses/frames that inject unusual opcodes into the send path","Catch IllegalArgumentException at the send boundary and log the offending opcode"],"exampleFix":"// before: hand-built frame with unmapped opcode\nFrameData f = new CustomFrame(someOpcode, payload);\nwebSocket.sendFrame(f);\n// after\nList<Framedata> frames = draft.createFrames(payloadBytes, true);\nwebSocket.sendFrame(frames.get(0));","handlingStrategy":"validation","validationCode":"// only send frames produced by the draft's own API\nList<Framedata> frames = draft.createFrames(payload, true); // never hand-build opcodes","typeGuard":null,"tryCatchPattern":"try {\n  webSocket.sendFrame(frame);\n} catch (IllegalArgumentException e) {\n  log.error(\"Unsupported opcode for this draft: {}\", e.getMessage());\n}","preventionTips":["Use draft.createFrames(...) rather than constructing Framedata manually","Keep library and custom frame code on the same Java-WebSocket version","Never inject opcodes outside 0-2 and 8-10"],"tags":["websocket","opcode","invalid-enum","internal"],"backgroundTag":"invalid-enum-value","analyzedSha":"afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d","analyzedAt":"2026-09-09T14:39:47.546Z","contentChangedAt":"2026-09-09T14:39:47.546Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}