Skip to content

Commit 0735b52

Browse files
Copilotbrunoborges
andcommitted
Add defensive copies to collection getters to fix SpotBugs EI_EXPOSE_REP findings
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 2be4be7 commit 0735b52

11 files changed

Lines changed: 43 additions & 32 deletions

src/main/java/com/github/copilot/sdk/events/AssistantMessageEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
88
import com.fasterxml.jackson.annotation.JsonProperty;
99

10+
import java.util.Collections;
1011
import java.util.List;
1112

1213
/**
@@ -136,7 +137,7 @@ public void setContent(String content) {
136137
* @return the tool requests, or {@code null} if none
137138
*/
138139
public List<ToolRequest> getToolRequests() {
139-
return toolRequests;
140+
return toolRequests == null ? null : Collections.unmodifiableList(toolRequests);
140141
}
141142

142143
/**

src/main/java/com/github/copilot/sdk/events/AssistantUsageEvent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
88
import com.fasterxml.jackson.annotation.JsonProperty;
99

10+
import java.util.Collections;
1011
import java.util.Map;
1112

1213
/**
@@ -161,7 +162,7 @@ public void setParentToolCallId(String parentToolCallId) {
161162
}
162163

163164
public Map<String, Object> getQuotaSnapshots() {
164-
return quotaSnapshots;
165+
return quotaSnapshots == null ? null : Collections.unmodifiableMap(quotaSnapshots);
165166
}
166167

167168
public void setQuotaSnapshots(Map<String, Object> quotaSnapshots) {

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
910

@@ -115,7 +116,7 @@ public void setReasoningEffort(String reasoningEffort) {
115116

116117
/** Gets the tools. @return the tool definitions */
117118
public List<ToolDef> getTools() {
118-
return tools;
119+
return tools == null ? null : Collections.unmodifiableList(tools);
119120
}
120121

121122
/** Sets the tools. @param tools the tool definitions */
@@ -135,7 +136,7 @@ public void setSystemMessage(SystemMessageConfig systemMessage) {
135136

136137
/** Gets available tools. @return the tool names */
137138
public List<String> getAvailableTools() {
138-
return availableTools;
139+
return availableTools == null ? null : Collections.unmodifiableList(availableTools);
139140
}
140141

141142
/** Sets available tools. @param availableTools the tool names */
@@ -145,7 +146,7 @@ public void setAvailableTools(List<String> availableTools) {
145146

146147
/** Gets excluded tools. @return the tool names */
147148
public List<String> getExcludedTools() {
148-
return excludedTools;
149+
return excludedTools == null ? null : Collections.unmodifiableList(excludedTools);
149150
}
150151

151152
/** Sets excluded tools. @param excludedTools the tool names */
@@ -215,7 +216,7 @@ public void setStreaming(Boolean streaming) {
215216

216217
/** Gets MCP servers. @return the servers map */
217218
public Map<String, Object> getMcpServers() {
218-
return mcpServers;
219+
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
219220
}
220221

221222
/** Sets MCP servers. @param mcpServers the servers map */
@@ -225,7 +226,7 @@ public void setMcpServers(Map<String, Object> mcpServers) {
225226

226227
/** Gets custom agents. @return the agents */
227228
public List<CustomAgentConfig> getCustomAgents() {
228-
return customAgents;
229+
return customAgents == null ? null : Collections.unmodifiableList(customAgents);
229230
}
230231

231232
/** Sets custom agents. @param customAgents the agents */
@@ -245,7 +246,7 @@ public void setInfiniteSessions(InfiniteSessionConfig infiniteSessions) {
245246

246247
/** Gets skill directories. @return the skill directories */
247248
public List<String> getSkillDirectories() {
248-
return skillDirectories;
249+
return skillDirectories == null ? null : Collections.unmodifiableList(skillDirectories);
249250
}
250251

251252
/** Sets skill directories. @param skillDirectories the directories */
@@ -255,7 +256,7 @@ public void setSkillDirectories(List<String> skillDirectories) {
255256

256257
/** Gets disabled skills. @return the disabled skill names */
257258
public List<String> getDisabledSkills() {
258-
return disabledSkills;
259+
return disabledSkills == null ? null : Collections.unmodifiableList(disabledSkills);
259260
}
260261

261262
/** Sets disabled skills. @param disabledSkills the skill names to disable */

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
910

@@ -51,7 +52,7 @@ public class ResumeSessionConfig {
5152
* @return the list of tool definitions
5253
*/
5354
public List<ToolDefinition> getTools() {
54-
return tools;
55+
return tools == null ? null : Collections.unmodifiableList(tools);
5556
}
5657

5758
/**
@@ -249,7 +250,7 @@ public ResumeSessionConfig setStreaming(boolean streaming) {
249250
* @return the MCP servers map
250251
*/
251252
public Map<String, Object> getMcpServers() {
252-
return mcpServers;
253+
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
253254
}
254255

255256
/**
@@ -270,7 +271,7 @@ public ResumeSessionConfig setMcpServers(Map<String, Object> mcpServers) {
270271
* @return the list of custom agent configurations
271272
*/
272273
public List<CustomAgentConfig> getCustomAgents() {
273-
return customAgents;
274+
return customAgents == null ? null : Collections.unmodifiableList(customAgents);
274275
}
275276

276277
/**
@@ -292,7 +293,7 @@ public ResumeSessionConfig setCustomAgents(List<CustomAgentConfig> customAgents)
292293
* @return the list of skill directory paths
293294
*/
294295
public List<String> getSkillDirectories() {
295-
return skillDirectories;
296+
return skillDirectories == null ? null : Collections.unmodifiableList(skillDirectories);
296297
}
297298

298299
/**
@@ -313,7 +314,7 @@ public ResumeSessionConfig setSkillDirectories(List<String> skillDirectories) {
313314
* @return the list of disabled skill names
314315
*/
315316
public List<String> getDisabledSkills() {
316-
return disabledSkills;
317+
return disabledSkills == null ? null : Collections.unmodifiableList(disabledSkills);
317318
}
318319

319320
/**

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
910

@@ -91,7 +92,7 @@ public void setReasoningEffort(String reasoningEffort) {
9192

9293
/** Gets the tools. @return the tool definitions */
9394
public List<ToolDef> getTools() {
94-
return tools;
95+
return tools == null ? null : Collections.unmodifiableList(tools);
9596
}
9697

9798
/** Sets the tools. @param tools the tool definitions */
@@ -171,7 +172,7 @@ public void setStreaming(Boolean streaming) {
171172

172173
/** Gets MCP servers. @return the servers map */
173174
public Map<String, Object> getMcpServers() {
174-
return mcpServers;
175+
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
175176
}
176177

177178
/** Sets MCP servers. @param mcpServers the servers map */
@@ -181,7 +182,7 @@ public void setMcpServers(Map<String, Object> mcpServers) {
181182

182183
/** Gets custom agents. @return the agents */
183184
public List<CustomAgentConfig> getCustomAgents() {
184-
return customAgents;
185+
return customAgents == null ? null : Collections.unmodifiableList(customAgents);
185186
}
186187

187188
/** Sets custom agents. @param customAgents the agents */
@@ -191,7 +192,7 @@ public void setCustomAgents(List<CustomAgentConfig> customAgents) {
191192

192193
/** Gets skill directories. @return the directories */
193194
public List<String> getSkillDirectories() {
194-
return skillDirectories;
195+
return skillDirectories == null ? null : Collections.unmodifiableList(skillDirectories);
195196
}
196197

197198
/** Sets skill directories. @param skillDirectories the directories */
@@ -201,7 +202,7 @@ public void setSkillDirectories(List<String> skillDirectories) {
201202

202203
/** Gets disabled skills. @return the disabled skill names */
203204
public List<String> getDisabledSkills() {
204-
return disabledSkills;
205+
return disabledSkills == null ? null : Collections.unmodifiableList(disabledSkills);
205206
}
206207

207208
/** Sets disabled skills. @param disabledSkills the skill names to disable */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89

910
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -57,7 +58,7 @@ public void setPrompt(String prompt) {
5758

5859
/** Gets the attachments. @return the list of attachments */
5960
public List<Attachment> getAttachments() {
60-
return attachments;
61+
return attachments == null ? null : Collections.unmodifiableList(attachments);
6162
}
6263

6364
/** Sets the attachments. @param attachments the list of attachments */

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
910

@@ -127,7 +128,7 @@ public SessionConfig setReasoningEffort(String reasoningEffort) {
127128
* @return the list of tool definitions
128129
*/
129130
public List<ToolDefinition> getTools() {
130-
return tools;
131+
return tools == null ? null : Collections.unmodifiableList(tools);
131132
}
132133

133134
/**
@@ -179,7 +180,7 @@ public SessionConfig setSystemMessage(SystemMessageConfig systemMessage) {
179180
* @return the list of available tool names
180181
*/
181182
public List<String> getAvailableTools() {
182-
return availableTools;
183+
return availableTools == null ? null : Collections.unmodifiableList(availableTools);
183184
}
184185

185186
/**
@@ -202,7 +203,7 @@ public SessionConfig setAvailableTools(List<String> availableTools) {
202203
* @return the list of excluded tool names
203204
*/
204205
public List<String> getExcludedTools() {
205-
return excludedTools;
206+
return excludedTools == null ? null : Collections.unmodifiableList(excludedTools);
206207
}
207208

208209
/**
@@ -369,7 +370,7 @@ public SessionConfig setStreaming(boolean streaming) {
369370
* @return the MCP servers map
370371
*/
371372
public Map<String, Object> getMcpServers() {
372-
return mcpServers;
373+
return mcpServers == null ? null : Collections.unmodifiableMap(mcpServers);
373374
}
374375

375376
/**
@@ -393,7 +394,7 @@ public SessionConfig setMcpServers(Map<String, Object> mcpServers) {
393394
* @return the list of custom agent configurations
394395
*/
395396
public List<CustomAgentConfig> getCustomAgents() {
396-
return customAgents;
397+
return customAgents == null ? null : Collections.unmodifiableList(customAgents);
397398
}
398399

399400
/**
@@ -445,7 +446,7 @@ public SessionConfig setInfiniteSessions(InfiniteSessionConfig infiniteSessions)
445446
* @return the list of skill directory paths
446447
*/
447448
public List<String> getSkillDirectories() {
448-
return skillDirectories;
449+
return skillDirectories == null ? null : Collections.unmodifiableList(skillDirectories);
449450
}
450451

451452
/**
@@ -470,7 +471,7 @@ public SessionConfig setSkillDirectories(List<String> skillDirectories) {
470471
* @return the list of disabled skill names
471472
*/
472473
public List<String> getDisabledSkills() {
473-
return disabledSkills;
474+
return disabledSkills == null ? null : Collections.unmodifiableList(disabledSkills);
474475
}
475476

476477
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89

910
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -55,7 +56,7 @@ public SessionEndHookOutput setSuppressOutput(Boolean suppressOutput) {
5556
* @return the cleanup actions, or {@code null}
5657
*/
5758
public List<String> getCleanupActions() {
58-
return cleanupActions;
59+
return cleanupActions == null ? null : Collections.unmodifiableList(cleanupActions);
5960
}
6061

6162
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.Map;
89

910
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -52,7 +53,7 @@ public SessionStartHookOutput setAdditionalContext(String additionalContext) {
5253
* @return the modified configuration map, or {@code null}
5354
*/
5455
public Map<String, Object> getModifiedConfig() {
55-
return modifiedConfig;
56+
return modifiedConfig == null ? null : Collections.unmodifiableMap(modifiedConfig);
5657
}
5758

5859
/**

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package com.github.copilot.sdk.json;
66

7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
910

@@ -80,7 +81,7 @@ public ToolResultObject setTextResultForLlm(String textResultForLlm) {
8081
* @return the list of binary results
8182
*/
8283
public List<ToolBinaryResult> getBinaryResultsForLlm() {
83-
return binaryResultsForLlm;
84+
return binaryResultsForLlm == null ? null : Collections.unmodifiableList(binaryResultsForLlm);
8485
}
8586

8687
/**
@@ -164,7 +165,7 @@ public ToolResultObject setSessionLog(String sessionLog) {
164165
* @return the telemetry map
165166
*/
166167
public Map<String, Object> getToolTelemetry() {
167-
return toolTelemetry;
168+
return toolTelemetry == null ? null : Collections.unmodifiableMap(toolTelemetry);
168169
}
169170

170171
public ToolResultObject setToolTelemetry(Map<String, Object> toolTelemetry) {

0 commit comments

Comments
 (0)