{"record":{"id":"d7d147bd23d75cf0","repo":"TooTallNate/Java-WebSocket","slug":"parameter-must-not-be-null","errorCode":null,"errorMessage":"parameter must not be null","messagePattern":"parameter must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/SSLSocketChannel.java","lineNumber":134,"sourceCode":"   * to this value should normally cause no capacity problems. However, some implementations violate\n   * the specification and generate large records up to 32 KB. If the {@link\n   * SSLEngine#unwrap(ByteBuffer, ByteBuffer)} detects large inbound packets, the buffer sizes\n   * returned by SSLSession will be updated dynamically, so the this peer should check for overflow\n   * conditions and enlarge the buffer using the session's (updated) buffer size.\n   */\n  private ByteBuffer peerNetData;\n\n  /**\n   * Will be used to execute tasks that may emerge during handshake in parallel with the server's\n   * main thread.\n   */\n  private ExecutorService executor;\n\n\n  public SSLSocketChannel(SocketChannel inputSocketChannel, SSLEngine inputEngine,\n      ExecutorService inputExecutor, SelectionKey key) throws IOException {\n    if (inputSocketChannel == null || inputEngine == null || executor == inputExecutor) {\n      throw new IllegalArgumentException(\"parameter must not be null\");\n    }\n\n    this.socketChannel = inputSocketChannel;\n    this.engine = inputEngine;\n    this.executor = inputExecutor;\n    myNetData = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());\n    peerNetData = ByteBuffer.allocate(engine.getSession().getPacketBufferSize());\n    this.engine.beginHandshake();\n    if (doHandshake()) {\n      if (key != null) {\n        key.interestOps(key.interestOps() | SelectionKey.OP_WRITE);\n      }\n    } else {\n      try {\n        socketChannel.close();\n      } catch (IOException e) {\n        log.error(\"Exception during the closing of the channel\", e);\n      }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/SSLSocketChannel.java#L116-L152","documentation":"The SSLSocketChannel constructor requires a non-null SocketChannel, SSLEngine, and ExecutorService. Note the source contains a real bug: it checks `executor == inputExecutor` (field, still null at that point) instead of `inputExecutor == null`, so the intended null-check for the executor is broken and a null executor is only caught indirectly later. If any checked argument is null, IllegalArgumentException('parameter must not be null') is thrown at construction time.","triggerScenarios":"Passing null for inputSocketChannel or inputEngine to new SSLSocketChannel(...). A null inputExecutor is NOT reliably rejected due to the `executor == inputExecutor` bug (it throws only if the field is non-null, which it never is in the constructor).","commonSituations":"Building an SSL-enabled WebSocketServer where the SSLEngine failed to create (bad keystore) or the socket channel was null after an accept failure, and the null was passed straight through.","solutions":["Check each argument for null before constructing SSLSocketChannel and fail with a clear message","Fix or verify the library version: newer versions check inputExecutor == null; upgrade if you rely on executor validation","Ensure SSLEngine creation (SSLContext) and socketChannel acquisition succeeded before wiring the channel"],"exampleFix":"// before\nnew SSLSocketChannel(channel, null, executor, key); // throws\n// after\nif (channel == null || sslEngine == null || executor == null) {\n  throw new IllegalArgumentException(\"channel, sslEngine and executor are required\");\n}\nnew SSLSocketChannel(channel, sslEngine, executor, key);","handlingStrategy":"type-guard","validationCode":"java.util.Objects.requireNonNull(channel, \"channel\");\njava.util.Objects.requireNonNull(sslEngine, \"sslEngine\");\njava.util.Objects.requireNonNull(executor, \"executor\");","typeGuard":"boolean argsValid = (channel != null && sslEngine != null && executor != null);","tryCatchPattern":"try { new SSLSocketChannel(ch, engine, exec, key); } catch (IllegalArgumentException e) { log.error(\"SSL channel wiring failed: {}\", e.getMessage()); }","preventionTips":["Build the SSLEngine from SSLContext before constructing the channel and check for null","Verify your library version handles the inputExecutor null-check (the shown source has an `executor == inputExecutor` bug)","Wrap manual channel wiring in helper methods that assert arguments"],"tags":["websocket","ssl","null-check","constructor"],"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"}