{"record":{"id":"25feaeb9799f8b88","repo":"TooTallNate/Java-WebSocket","slug":"supplied-opcode-is-invalid","errorCode":null,"errorMessage":"Supplied opcode is invalid","messagePattern":"Supplied opcode is invalid","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/framing/FramedataImpl1.java","lineNumber":246,"sourceCode":"  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  }\n\n  @Override\n  public boolean equals(Object o) {\n    if (this == o) {\n      return true;\n    }\n    if (o == null || getClass() != o.getClass()) {\n      return false;\n    }\n\n    FramedataImpl1 that = (FramedataImpl1) o;\n\n    if (fin != that.fin) {\n      return false;\n    }\n    if (transferemasked != that.transferemasked) {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/framing/FramedataImpl1.java#L228-L264","documentation":"FramedataImpl1.get(Opcode) throws IllegalArgumentException('Supplied opcode is invalid') when it reaches the default branch of its switch. All defined opcodes are handled, so this fires only for opcodes outside the known enum set — practically unreachable unless a new Opcode enum constant was added without extending the factory, or exotic classloading yields an unexpected value.","triggerScenarios":"Calling FramedataImpl1.get() with an Opcode value that has no case in the switch (e.g. a newer enum constant after a library upgrade, before the factory was updated).","commonSituations":"Version mismatch where custom code or a fork added an Opcode constant but did not update FramedataImpl1.get().","solutions":["Ensure all Opcode enum values are covered in FramedataImpl1.get(); add the missing case","Update the library to matching versions so enum and factory are consistent","Add a fallback mapping (e.g. treat unknown as CONTINUOUS) instead of relying on the default throw"],"exampleFix":"// before (fork added an opcode but not a case)\ncase CONTINUOUS: return new ContinuousFrame();\ndefault: throw new IllegalArgumentException(\"Supplied opcode is invalid\");\n// after\ncase CONTINUOUS: return new ContinuousFrame();\ncase MY_CUSTOM: return new ContinuousFrame();\ndefault: throw new IllegalArgumentException(\"Supplied opcode is invalid\");","handlingStrategy":"try-catch","validationCode":"if (opcode == null || !KNOWN_OPCODES.contains(opcode)) {\n  throw new IllegalArgumentException(\"unsupported opcode: \" + opcode);\n}","typeGuard":"boolean isMappedOpcode(Opcode o) {\n  switch (o) {\n    case PING: case PONG: case CLOSING: case CONTINUOUS:\n    case TEXT: case BINARY:\n      return true;\n    default: return false;\n  }\n}","tryCatchPattern":"try {\n  FramedataImpl1 frame = FramedataImpl1.get(opcode);\n} catch (IllegalArgumentException e) {\n  // log opcode; use ContinuousFrame as fallback or drop the frame\n}","preventionTips":["Keep Opcode enum and FramedataImpl1.get() switch in sync, especially in forks","After library upgrades, re-verify any custom opcode handling","Add a unit test iterating all Opcode values through get()"],"tags":["websocket","enum","factory-method"],"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"}