{"record":{"id":"c36dc58b46f2e6e4","repo":"TooTallNate/Java-WebSocket","slug":"only-opcode-binary-or-opcode-text-are-allowed","errorCode":null,"errorMessage":"Only Opcode.BINARY or  Opcode.TEXT are allowed","messagePattern":"Only Opcode\\.BINARY or  Opcode\\.TEXT are allowed","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft.java","lineNumber":212,"sourceCode":"\n  public abstract List<Framedata> createFrames(ByteBuffer binary, boolean mask);\n\n  public abstract List<Framedata> createFrames(String text, boolean mask);\n\n\n  /**\n   * Handle the frame specific to the draft\n   *\n   * @param webSocketImpl the websocketimpl used for this draft\n   * @param frame         the frame which is supposed to be handled\n   * @throws InvalidDataException will be thrown on invalid data\n   */\n  public abstract void processFrame(WebSocketImpl webSocketImpl, Framedata frame)\n      throws InvalidDataException;\n\n  public List<Framedata> continuousFrame(Opcode op, ByteBuffer buffer, boolean fin) {\n    if (op != Opcode.BINARY && op != Opcode.TEXT) {\n      throw new IllegalArgumentException(\"Only Opcode.BINARY or  Opcode.TEXT are allowed\");\n    }\n    DataFrame bui = null;\n    if (continuousFrameType != null) {\n      bui = new ContinuousFrame();\n    } else {\n      continuousFrameType = op;\n      if (op == Opcode.BINARY) {\n        bui = new BinaryFrame();\n      } else if (op == Opcode.TEXT) {\n        bui = new TextFrame();\n      }\n    }\n    bui.setPayload(buffer);\n    bui.setFin(fin);\n    try {\n      bui.isValid();\n    } catch (InvalidDataException e) {\n      throw new IllegalArgumentException(","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft.java#L194-L230","documentation":"Draft.continuousFrame builds a frame for streaming messages, but per RFC 6455 only TEXT and BINARY opcodes are valid for message data frames; control/other opcodes (PING, PONG, CLOSE, CONTINUOUS) are rejected with this IllegalArgumentException before any frame is created.","triggerScenarios":"Calling draft.continuousFrame(Opcode.PING/PONG/CLOSE/CONTINUOUS, buffer, fin) directly, or code that computes the Opcode dynamically and passes a control opcode.","commonSituations":"Low-level users of the draft API hand-rolling fragmentation instead of using WebSocketImpl.send, refactoring that mixes control-frame creation with data-frame streaming, copying examples that pass Opcode values around.","solutions":["Pass only Opcode.TEXT or Opcode.BINARY to continuousFrame","Use the high-level WebSocket send methods (send/sendFragmentedFrame) instead of calling draft APIs directly","For ping/pong/close, use the dedicated API (webSocket.sendPing, close) rather than building frames manually","Add a guard/assert on the opcode before calling"],"exampleFix":"// before\ndraft.continuousFrame(Opcode.PING, payload, true);\n// after\ndraft.continuousFrame(Opcode.BINARY, payload, true);","handlingStrategy":"validation","validationCode":"private static void requireDataFrame(Opcode op) {\n  if (op != Opcode.TEXT && op != Opcode.BINARY)\n    throw new IllegalArgumentException(\"continuousFrame requires TEXT or BINARY, got \" + op);\n}","typeGuard":null,"tryCatchPattern":"try {\n  frames = draft.continuousFrame(op, buffer, fin);\n} catch (IllegalArgumentException e) {\n  logger.error(\"Invalid opcode for data frame: {}\", e.getMessage());\n}","preventionTips":["Only pass TEXT/BINARY into frame-building APIs","Use high-level send() methods instead of draft-level frame construction","Use dedicated sendPing/sendPong/close for control frames"],"tags":["websocket","frames","illegal-argument"],"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"}