{"record":{"id":"c66c17adb2250ac1","repo":"TooTallNate/Java-WebSocket","slug":"supplied-opcode-cannot-be-null","errorCode":null,"errorMessage":"Supplied opcode cannot be null","messagePattern":"Supplied opcode cannot be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/framing/FramedataImpl1.java","lineNumber":230,"sourceCode":"\n  /**\n   * Set the tranferemask of this frame to the provided boolean\n   *\n   * @param transferemasked true if transferemasked has to be set\n   */\n  public void setTransferemasked(boolean transferemasked) {\n    this.transferemasked = transferemasked;\n  }\n\n  /**\n   * Get a frame with a specific opcode\n   *\n   * @param opcode the opcode representing the frame\n   * @return the frame with a specific opcode\n   */\n  public static FramedataImpl1 get(Opcode opcode) {\n    if (opcode == null) {\n      throw new IllegalArgumentException(\"Supplied opcode cannot be null\");\n    }\n    switch (opcode) {\n      case PING:\n        return new PingFrame();\n      case PONG:\n        return new PongFrame();\n      case TEXT:\n        return new TextFrame();\n      case BINARY:\n        return new BinaryFrame();\n      case CLOSING:\n        return new CloseFrame();\n      case CONTINUOUS:\n        return new ContinuousFrame();\n      default:\n        throw new IllegalArgumentException(\"Supplied opcode is invalid\");\n    }\n  }","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/framing/FramedataImpl1.java#L212-L248","documentation":"FramedataImpl1.get(Opcode) is a static factory that maps a WebSocket Opcode to a concrete frame class (PingFrame, PongFrame, etc.). It throws IllegalArgumentException when the supplied opcode is null because there is no frame type to map to.","triggerScenarios":"Calling FramedataImpl1.get(null), often when the opcode comes from an uninitialized field, an unparseable frame header, or a lookup that returned null.","commonSituations":"Custom protocol handling code building frames programmatically, or wrapping a parsing routine that can return null opcodes.","solutions":["Check the opcode for null before calling FramedataImpl1.get()","Trace where the null opcode originates (usually failed header parsing) and handle it there","Use Opcode.valueOf/lookup with a fallback default instead of passing through possibly-null values"],"exampleFix":"// before\nFramedataImpl1 frame = FramedataImpl1.get(opcode);\n// after\nif (opcode == null) { opcode = Opcode.CONTINUOUS; }\nFramedataImpl1 frame = FramedataImpl1.get(opcode);","handlingStrategy":"type-guard","validationCode":"if (opcode == null) {\n  throw new IllegalArgumentException(\"opcode required\");\n}","typeGuard":"boolean isKnownOpcode(Opcode o) {\n  return o != null && java.util.EnumSet.allOf(Opcode.class).contains(o);\n}","tryCatchPattern":"try {\n  FramedataImpl1 frame = FramedataImpl1.get(opcode);\n} catch (IllegalArgumentException e) {\n  // fall back to a safe frame type or abort the send\n}","preventionTips":["Initialize opcode fields with a concrete default instead of null","Null-check values coming from header parsing before factory calls"],"tags":["websocket","null-argument","factory-method"],"backgroundTag":"null-argument","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"}