{"record":{"id":"246eeb6e2b70fa7a","repo":"TooTallNate/Java-WebSocket","slug":"size-representation-not-supported-specified","errorCode":null,"errorMessage":"Size representation not supported/specified","messagePattern":"Size representation not supported/specified","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft_6455.java","lineNumber":509,"sourceCode":"      one |= getRSVByte(2);\n    }\n    if (framedata.isRSV3()) {\n      one |= getRSVByte(3);\n    }\n    buf.put(one);\n    byte[] payloadlengthbytes = toByteArray(mes.remaining(), sizebytes);\n    assert (payloadlengthbytes.length == sizebytes);\n\n    if (sizebytes == 1) {\n      buf.put((byte) (payloadlengthbytes[0] | getMaskByte(mask)));\n    } else if (sizebytes == 2) {\n      buf.put((byte) ((byte) 126 | getMaskByte(mask)));\n      buf.put(payloadlengthbytes);\n    } else if (sizebytes == 8) {\n      buf.put((byte) ((byte) 127 | getMaskByte(mask)));\n      buf.put(payloadlengthbytes);\n    } else {\n      throw new IllegalStateException(\"Size representation not supported/specified\");\n    }\n    if (mask) {\n      ByteBuffer maskkey = ByteBuffer.allocate(4);\n      maskkey.putInt(reuseableRandom.nextInt());\n      buf.put(maskkey.array());\n      for (int i = 0; mes.hasRemaining(); i++) {\n        buf.put((byte) (mes.get() ^ maskkey.get(i % 4)));\n      }\n    } else {\n      buf.put(mes);\n      //Reset the position of the bytebuffer e.g. for additional use\n      mes.flip();\n    }\n    assert (buf.remaining() == 0) : buf.remaining();\n    buf.flip();\n    return buf;\n  }\n","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft_6455.java#L491-L527","documentation":"createByteBufferFromFramedata writes the frame length using 7/16/64-bit representations; the computed sizebytes value must be 0, 2, or 8. Any other value means an internal inconsistency (invalid payload length) and the code throws this IllegalStateException before the frame can be serialized.","triggerScenarios":"Attempting to serialize a frame whose payload length does not map to a supported length encoding, usually via createBinaryFrame on a frame built with a corrupted or out-of-range length (negative payload or length overflow beyond 64-bit representation).","commonSituations":"Custom Draft/subclass code building frames with hand-set payload lengths, payload ByteBuffers with negative remaining(), constructing frames with sizes outside RFC 6455 bounds.","solutions":["Ensure the payload ByteBuffer has a non-negative, RFC-valid remaining() size before createBinaryFrame","Do not manually mutate frame length fields; build frames via the library APIs (send, continuousFrame)","Check that total message sizes stay within 64-bit unsigned length limits","Catch/inspect in a debugger to find where the bad length originates"],"exampleFix":"// before\nframe.setPayload(ByteBuffer.allocate(-1));\n// after\nframe.setPayload(ByteBuffer.allocate(payloadSize)); // payloadSize >= 0","handlingStrategy":"validation","validationCode":"private static boolean isEncodableLength(ByteBuffer payload) {\n  return payload != null && payload.remaining() >= 0;\n}\n// call before createBinaryFrame: if (!isEncodableLength(payload)) skip;","typeGuard":"boolean isEncodableLength(ByteBuffer b) { return b != null && b.remaining() >= 0; }","tryCatchPattern":"try {\n  ws.send(payload);\n} catch (IllegalStateException e) {\n  if (\"Size representation not supported/specified\".equals(e.getMessage()))\n    logger.error(\"Frame length cannot be encoded — payload buffer corrupted\");\n}","preventionTips":["Build frames only through library APIs, never set length fields manually","Verify payload buffers are allocated with non-negative sizes","Investigate custom Draft subclasses that tamper with frame lengths"],"tags":["websocket","frames","internal-error"],"backgroundTag":"internal-invariant-violation","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"}