{"record":{"id":"27537d801c6b9745","repo":"github/copilot-sdk","slug":"options-must-not-be-null","errorCode":null,"errorMessage":"options must not be null","messagePattern":"options must not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/CopilotSession.java","lineNumber":2237,"sourceCode":"     * session.setModel(new SetModelOptions().setModel(\"auto\").setAutoTier(AutoTier.INTELLIGENCE)).get();\n     * session.setModel(new SetModelOptions().setModel(\"auto\").setResetAutoTier(true)).get();\n     * }</pre>\n     *\n     * @param options\n     *            the switch settings; the model ID is required\n     * @return a future that completes when the model switch is acknowledged\n     * @throws IllegalArgumentException\n     *             if {@code options} is {@code null}, if it carries no model ID, or\n     *             if it requests both an explicit Auto tier and a return to\n     *             provider-default Auto routing\n     * @throws IllegalStateException\n     *             if this session has been terminated\n     * @since 1.6.0\n     */\n    public CompletableFuture<Void> setModel(com.github.copilot.rpc.SetModelOptions options) {\n        ensureNotTerminated();\n        if (options == null) {\n            throw new IllegalArgumentException(\"options must not be null\");\n        }\n        if (options.getModel() == null) {\n            throw new IllegalArgumentException(\"options must specify a model\");\n        }\n        if (options.getAutoTier() != null && options.isResetAutoTier()) {\n            throw new IllegalArgumentException(\n                    \"setModel cannot combine an explicit autoTier with resetAutoTier; choose one\");\n        }\n        var generatedReasoningSummary = options.getReasoningSummary() == null\n                ? null\n                : com.github.copilot.generated.rpc.ReasoningSummary.fromValue(options.getReasoningSummary());\n        var params = new SessionModelSwitchToParams(sessionId, options.getModel(),\n                toGeneratedAutoTier(options.getAutoTier()), options.getReasoningEffort(), generatedReasoningSummary,\n                null, toGeneratedCapabilities(options.getModelCapabilities()), null, null, null, null, null, null, null,\n                null, null);\n        if (!options.isResetAutoTier()) {\n            return getRpc().model.switchTo(params).thenApply(r -> null);\n        }","sourceCodeStart":2219,"sourceCodeEnd":2255,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/CopilotSession.java#L2219-L2255","documentation":"CopilotSession.setModel(SetModelOptions) validates its argument before issuing the RPC and throws IllegalArgumentException('options must not be null') when called with null. The SDK requires an options object even if only changing the model, so callers must construct SetModelOptions.","triggerScenarios":"Calling session.setModel(null) after the session is confirmed non-terminated (CopilotSession.java:2237). Note ensureNotTerminated() runs first, so a terminated session throws IllegalStateException instead.","commonSituations":"A caller builds options conditionally (e.g. only when a model preference exists) and passes the null result straight to setModel; typical in config-driven code where the model setting is absent.","solutions":["Pass a constructed SetModelOptions instance with at least a model value set.","Return early when no model option is configured instead of calling setModel with null.","Add a caller-side null check before invoking setModel."],"exampleFix":"// before\nsession.setModel(config.getModelOptions()); // null when unset\n// after\nvar options = config.getModelOptions();\nif (options != null) {\n    session.setModel(options);\n}","handlingStrategy":"type-guard","validationCode":"if (options == null) {\n    return; // nothing to set\n}","typeGuard":"boolean hasOptions(com.github.copilot.rpc.SetModelOptions o) { return o != null; }","tryCatchPattern":"try {\n    session.setModel(options);\n} catch (IllegalArgumentException e) {\n    LOG.warning(\"setModel rejected: \" + e.getMessage());\n}","preventionTips":["Never forward nullable config straight into setModel; check before calling.","Build SetModelOptions in a single factory that guarantees a usable instance.","Skip the setModel call entirely when no model preference is configured."],"tags":["null-argument","validation","set-model"],"backgroundTag":"null-argument","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}