{"record":{"id":"d28260ce4853b48e","repo":"TooTallNate/Java-WebSocket","slug":"unknown-opcode-opcode","errorCode":null,"errorMessage":"Unknown opcode {opcode}","messagePattern":"Unknown opcode (.+?)","errorType":"exception","errorClass":"InvalidFrameException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft_6455.java","lineNumber":888,"sourceCode":"\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\n      default:\n        throw new InvalidFrameException(\"Unknown opcode \" + (short) opcode);\n    }\n  }\n\n  @Override\n  public void processFrame(WebSocketImpl webSocketImpl, Framedata frame)\n      throws InvalidDataException {\n    Opcode curop = frame.getOpcode();\n    if (curop == Opcode.CLOSING) {\n      processFrameClosing(webSocketImpl, frame);\n    } else if (curop == Opcode.PING) {\n      webSocketImpl.getWebSocketListener().onWebsocketPing(webSocketImpl, frame);\n    } else if (curop == Opcode.PONG) {\n      webSocketImpl.updateLastPong();\n      webSocketImpl.getWebSocketListener().onWebsocketPong(webSocketImpl, frame);\n    } else if (!frame.isFin() || curop == Opcode.CONTINUOUS) {\n      processFrameContinuousAndNonFin(webSocketImpl, frame, curop);\n    } else if (currentContinuousFrame != null) {\n      log.error(\"Protocol error: Continuous frame sequence not completed.\");","sourceCodeStart":870,"sourceCodeEnd":906,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft_6455.java#L870-L906","documentation":"Draft_6455.toOpcode throws InvalidFrameException(\"Unknown opcode <n>\") when an incoming frame header carries an opcode in the reserved range 3-7 (non-control) or 11-15 (control), which are not yet defined by RFC 6455. The library cannot interpret such a frame and rejects it as invalid.","triggerScenarios":"Receiving a frame whose 4-bit opcode field is 3-7 or 11-15; toOpcode's switch default throws. Often from protocol-violating peers, extensions negotiating opcodes this library doesn't support, or corrupted stream data.","commonSituations":"Peer implementing newer/proprietary opcodes; desynchronization causing garbage bytes to be parsed as opcodes; fuzz testing; protocol extensions (e.g. permessage-deflate variants) misbehaving.","solutions":["Fix or stop the peer from sending reserved opcodes; RFC 6455 receivers must fail the connection","Catch InvalidFrameException and close with protocol error (1002)","Check for stream desynchronization (partial reads, wrong framing) if garbage opcodes appear","Disable protocol extensions on either side that may emit unsupported opcodes"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// in your WebSocketListener\n@Override\npublic void onWebsocketError(WebSocket conn, Exception ex) {\n  if (ex instanceof InvalidFrameException && ex.getMessage().startsWith(\"Unknown opcode\")) {\n    conn.close(CloseFrame.PROTOCOL_ERROR, \"reserved opcode received\");\n  }\n}","preventionTips":["Fail the connection on reserved opcodes per RFC 6455 — do not try to interpret them","Investigate stream desynchronization if garbage opcodes appear repeatedly","Disable protocol extensions that emit opcodes this library cannot parse"],"tags":["websocket","opcode","rfc6455","protocol-violation"],"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"}