{"record":{"id":"13db2126b6e95366","repo":"eclipse-vertx/vert.x","slug":"this-should-be-a-close-frame","errorCode":null,"errorMessage":"This should be a close frame","messagePattern":"This should be a close frame","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"vertx-core/src/main/java/io/vertx/core/http/impl/websocket/WebSocketFrameImpl.java","lineNumber":246,"sourceCode":"  private void parseCloseFrame() {\n    int length = length();\n    if (length < 2) {\n      closeStatusCode = 1000;\n      closeReason = null;\n    } else {\n      int index = binaryData.readerIndex();\n      closeStatusCode = binaryData.getShort(index);\n      if (length == 2) {\n        closeReason = null;\n      } else {\n        closeReason = binaryData.toString(index + 2, length - 2, StandardCharsets.UTF_8);\n      }\n    }\n  }\n\n  private void checkClose() {\n    if (!isClose())\n      throw new IllegalStateException(\"This should be a close frame\");\n  }\n\n  @Override\n  public short closeStatusCode() {\n    checkClose();\n    if (!closeParsed)\n      parseCloseFrame();\n    return this.closeStatusCode;\n  }\n\n  @Override\n  public String closeReason() {\n    checkClose();\n    if (!closeParsed)\n      parseCloseFrame();\n    return this.closeReason;\n  }\n","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/eclipse-vertx/vert.x/blob/fb308bd8c3f12c79f4ae89bef67fadf6c80d036e/vertx-core/src/main/java/io/vertx/core/http/impl/websocket/WebSocketFrameImpl.java#L228-L264","documentation":"API misuse guard in WebSocketFrameImpl.checkClose: closeStatusCode() or closeReason() was called on a WebSocket frame that is not a CLOSE frame. Only close frames carry a status code and reason, so parsing them from other frame types is rejected (the internal isClose() check failed).","triggerScenarios":"Thrown at vertx-core/src/main/java/io/vertx/core/http/impl/websocket/WebSocketFrameImpl.java:246 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check frame.type() == WebSocketFrameType.CLOSE before reading closeStatusCode/closeReason","Handle binary/text frames separately from close frames"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fb308bd8c3f12c79f4ae89bef67fadf6c80d036e","analyzedAt":"2026-09-06T11:37:12.241Z","contentChangedAt":"2026-09-06T11:37:12.241Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}