TooTallNate/Java-WebSocket · error · IllegalArgumentException

Supplied opcode is invalid

Error message

Supplied opcode is invalid

What it means

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.

Solutions

  1. Ensure all Opcode enum values are covered in FramedataImpl1.get(); add the missing case
  2. Update the library to matching versions so enum and factory are consistent
  3. Add a fallback mapping (e.g. treat unknown as CONTINUOUS) instead of relying on the default throw

Example fix

// before (fork added an opcode but not a case)
case CONTINUOUS: return new ContinuousFrame();
default: throw new IllegalArgumentException("Supplied opcode is invalid");
// after
case CONTINUOUS: return new ContinuousFrame();
case MY_CUSTOM: return new ContinuousFrame();
default: throw new IllegalArgumentException("Supplied opcode is invalid");
Defensive patterns

Strategy: try-catch

Validate before calling

if (opcode == null || !KNOWN_OPCODES.contains(opcode)) {
  throw new IllegalArgumentException("unsupported opcode: " + opcode);
}

Type guard

boolean isMappedOpcode(Opcode o) {
  switch (o) {
    case PING: case PONG: case CLOSING: case CONTINUOUS:
    case TEXT: case BINARY:
      return true;
    default: return false;
  }
}

Try / catch

try {
  FramedataImpl1 frame = FramedataImpl1.get(opcode);
} catch (IllegalArgumentException e) {
  // log opcode; use ContinuousFrame as fallback or drop the frame
}

Prevention

When it happens

Trigger: 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).

Common situations: Version mismatch where custom code or a fork added an Opcode constant but did not update FramedataImpl1.get().

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09). Data as JSON: /api/errors/25feaeb9799f8b88. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/org/java_websocket/framing/FramedataImpl1.java:246

  public static FramedataImpl1 get(Opcode opcode) {
    if (opcode == null) {
      throw new IllegalArgumentException("Supplied opcode cannot be null");
    }
    switch (opcode) {
      case PING:
        return new PingFrame();
      case PONG:
        return new PongFrame();
      case TEXT:
        return new TextFrame();
      case BINARY:
        return new BinaryFrame();
      case CLOSING:
        return new CloseFrame();
      case CONTINUOUS:
        return new ContinuousFrame();
      default:
        throw new IllegalArgumentException("Supplied opcode is invalid");
    }
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    FramedataImpl1 that = (FramedataImpl1) o;

    if (fin != that.fin) {
      return false;
    }
    if (transferemasked != that.transferemasked) {

View on GitHub (pinned to afeacbf8c0)