Skip to content

Commit 9098d5a

Browse files
Copilotedburns
andauthored
Add null checks to all reference-type setters in CopilotClientOptions
Agent-Logs-Url: https://github.com/github/copilot-sdk-java/sessions/019cc9a8-a29a-49a5-a7ac-aa573931dfb8 Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
1 parent 296ccac commit 9098d5a

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/main/java/com/github/copilot/sdk/json/CopilotClientOptions.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import java.util.List;
88
import java.util.Map;
9+
import java.util.Objects;
910
import java.util.concurrent.CompletableFuture;
1011
import java.util.concurrent.Executor;
1112
import java.util.function.Supplier;
@@ -121,7 +122,7 @@ public String[] getCliArgs() {
121122
* @return this options instance for method chaining
122123
*/
123124
public CopilotClientOptions setCliArgs(String[] cliArgs) {
124-
this.cliArgs = cliArgs;
125+
this.cliArgs = Objects.requireNonNull(cliArgs, "cliArgs must not be null");
125126
return this;
126127
}
127128

@@ -138,12 +139,11 @@ public String getCliPath() {
138139
* Sets the path to the Copilot CLI executable.
139140
*
140141
* @param cliPath
141-
* the path to the CLI executable, or {@code null} to use "copilot"
142-
* from PATH
142+
* the path to the CLI executable
143143
* @return this options instance for method chaining
144144
*/
145145
public CopilotClientOptions setCliPath(String cliPath) {
146-
this.cliPath = cliPath;
146+
this.cliPath = Objects.requireNonNull(cliPath, "cliPath must not be null");
147147
return this;
148148
}
149149

@@ -170,7 +170,7 @@ public String getCliUrl() {
170170
* @return this options instance for method chaining
171171
*/
172172
public CopilotClientOptions setCliUrl(String cliUrl) {
173-
this.cliUrl = cliUrl;
173+
this.cliUrl = Objects.requireNonNull(cliUrl, "cliUrl must not be null");
174174
return this;
175175
}
176176

@@ -191,7 +191,7 @@ public String getCwd() {
191191
* @return this options instance for method chaining
192192
*/
193193
public CopilotClientOptions setCwd(String cwd) {
194-
this.cwd = cwd;
194+
this.cwd = Objects.requireNonNull(cwd, "cwd must not be null");
195195
return this;
196196
}
197197

@@ -214,7 +214,7 @@ public Map<String, String> getEnvironment() {
214214
* @return this options instance for method chaining
215215
*/
216216
public CopilotClientOptions setEnvironment(Map<String, String> environment) {
217-
this.environment = environment;
217+
this.environment = Objects.requireNonNull(environment, "environment must not be null");
218218
return this;
219219
}
220220

@@ -237,11 +237,11 @@ public Executor getExecutor() {
237237
* onto a dedicated thread pool or integrate with container-managed threading.
238238
*
239239
* @param executor
240-
* the executor to use, or {@code null} for the default
240+
* the executor to use
241241
* @return this options instance for fluent chaining
242242
*/
243243
public CopilotClientOptions setExecutor(Executor executor) {
244-
this.executor = executor;
244+
this.executor = Objects.requireNonNull(executor, "executor must not be null");
245245
return this;
246246
}
247247

@@ -265,7 +265,7 @@ public String getGitHubToken() {
265265
* @return this options instance for method chaining
266266
*/
267267
public CopilotClientOptions setGitHubToken(String gitHubToken) {
268-
this.gitHubToken = gitHubToken;
268+
this.gitHubToken = Objects.requireNonNull(gitHubToken, "gitHubToken must not be null");
269269
return this;
270270
}
271271

@@ -290,7 +290,7 @@ public String getGithubToken() {
290290
*/
291291
@Deprecated
292292
public CopilotClientOptions setGithubToken(String githubToken) {
293-
this.gitHubToken = githubToken;
293+
this.gitHubToken = Objects.requireNonNull(githubToken, "githubToken must not be null");
294294
return this;
295295
}
296296

@@ -313,7 +313,7 @@ public String getLogLevel() {
313313
* @return this options instance for method chaining
314314
*/
315315
public CopilotClientOptions setLogLevel(String logLevel) {
316-
this.logLevel = logLevel;
316+
this.logLevel = Objects.requireNonNull(logLevel, "logLevel must not be null");
317317
return this;
318318
}
319319

@@ -338,7 +338,7 @@ public Supplier<CompletableFuture<List<ModelInfo>>> getOnListModels() {
338338
* @return this options instance for method chaining
339339
*/
340340
public CopilotClientOptions setOnListModels(Supplier<CompletableFuture<List<ModelInfo>>> onListModels) {
341-
this.onListModels = onListModels;
341+
this.onListModels = Objects.requireNonNull(onListModels, "onListModels must not be null");
342342
return this;
343343
}
344344

@@ -378,16 +378,16 @@ public TelemetryConfig getTelemetry() {
378378
/**
379379
* Sets the OpenTelemetry configuration for the CLI server.
380380
* <p>
381-
* When set to a non-{@code null} value, the CLI server is started with
382-
* OpenTelemetry instrumentation enabled using the provided settings.
381+
* When set, the CLI server is started with OpenTelemetry instrumentation
382+
* enabled using the provided settings.
383383
*
384384
* @param telemetry
385385
* the telemetry configuration
386386
* @return this options instance for method chaining
387387
* @since 1.2.0
388388
*/
389389
public CopilotClientOptions setTelemetry(TelemetryConfig telemetry) {
390-
this.telemetry = telemetry;
390+
this.telemetry = Objects.requireNonNull(telemetry, "telemetry must not be null");
391391
return this;
392392
}
393393

src/test/java/com/github/copilot/sdk/CliServerManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ void startCliServerWithGitHubTokenAndNoExplicitUseLoggedInUser() throws Exceptio
199199

200200
@Test
201201
void startCliServerWithNullCliPath() throws Exception {
202-
// Test the null cliPath branch (defaults to "copilot")
203-
var options = new CopilotClientOptions().setCliPath(null).setUseStdio(true);
202+
// Test the default cliPath branch (defaults to "copilot" when not set)
203+
var options = new CopilotClientOptions().setUseStdio(true);
204204
var manager = new CliServerManager(options);
205205

206206
// "copilot" likely doesn't exist in the test env — that's fine

0 commit comments

Comments
 (0)