{"record":{"id":"f603b6263b8ff6ed","repo":"github/copilot-sdk","slug":"policy-must-not-be-null","errorCode":null,"errorMessage":"policy must not be null","messagePattern":"policy must not be null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/CopilotSession.java","lineNumber":501,"sourceCode":"     * <pre>{@code\n     * // Opt-in to suppress errors (continue dispatching despite errors)\n     * session.setEventErrorPolicy(EventErrorPolicy.SUPPRESS_AND_LOG_ERRORS);\n     * session.setEventErrorHandler((event, ex) -> logger.error(\"Handler failed, continuing: {}\", ex.getMessage(), ex));\n     * }</pre>\n     *\n     * @param policy\n     *            the error policy (default is\n     *            {@link EventErrorPolicy#PROPAGATE_AND_LOG_ERRORS})\n     * @throws IllegalStateException\n     *             if this session has been terminated\n     * @see EventErrorPolicy\n     * @see #setEventErrorHandler(EventErrorHandler)\n     * @since 1.0.8\n     */\n    public void setEventErrorPolicy(EventErrorPolicy policy) {\n        ensureNotTerminated();\n        if (policy == null) {\n            throw new NullPointerException(\"policy must not be null\");\n        }\n        this.eventErrorPolicy = policy;\n    }\n\n    /**\n     * Sends a simple text message to the Copilot session.\n     * <p>\n     * This is a convenience method equivalent to\n     * {@code send(new MessageOptions().setPrompt(prompt))}.\n     *\n     * @param prompt\n     *            the message text to send\n     * @return a future that resolves with the message ID assigned by the server\n     * @throws IllegalStateException\n     *             if this session has been terminated\n     * @see #send(MessageOptions)\n     */\n    public CompletableFuture<String> send(String prompt) {","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/CopilotSession.java#L483-L519","documentation":"setEventErrorPolicy stores the handler that decides how session event-processing errors are treated. A null policy would silently disable error handling, so the method explicitly throws NullPointerException with \"policy must not be null\".","triggerScenarios":"Calling session.setEventErrorPolicy(null), typically while attempting to \"remove\" the policy or passing an uninitialized field.","commonSituations":"Refactors that changed an EventErrorPolicy field default to null; clearing handlers by passing null instead of a no-op policy; configuration objects with missing policy values.","solutions":["Pass a non-null policy; to disable custom handling pass a benign default policy such as EventErrorPolicy.IGNORE (or library default)","Keep a static NO_OP EventErrorPolicy constant for clearing","Initialize policy fields with a default instead of null"],"exampleFix":"// before\nsession.setEventErrorPolicy(null);\n// after\nsession.setEventErrorPolicy(EventErrorPolicy.IGNORE); // or your default policy","handlingStrategy":"validation","validationCode":"if (policy == null) { policy = EventErrorPolicy.IGNORE; } // before calling","typeGuard":null,"tryCatchPattern":"try {\n    session.setEventErrorPolicy(policy);\n} catch (NullPointerException e) {\n    if (\"policy must not be null\".equals(e.getMessage())) {\n        session.setEventErrorPolicy(EventErrorPolicy.IGNORE);\n    }\n}","preventionTips":["Never pass null to setEventErrorPolicy; use a no-op/default policy instead","Initialize EventErrorPolicy fields with defaults, not null","Audit code that 'clears' handlers by passing null"],"tags":["null-argument","event-handling","api-misuse"],"backgroundTag":"null-argument","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}