Skip to content

refactor: use Optional return types instead of nullable boxed primitives in public API#189

Draft
Copilot wants to merge 3 commits into
mainfrom
copilot/update-public-api-to-use-optional
Draft

refactor: use Optional return types instead of nullable boxed primitives in public API#189
Copilot wants to merge 3 commits into
mainfrom
copilot/update-public-api-to-use-optional

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Resolves #187


Before the change?

  • ~30 public getters on mutable config/builder classes return nullable boxed types (Boolean, Integer, Double) — a C# idiom carried over from the reference implementation. The "may be absent" contract is invisible in type signatures and forgotten null-checks compile fine but NPE at runtime.

After the change?

  • Getters return Optional<Boolean>, OptionalInt, or OptionalDouble. Setters take primitives (boolean, int, double). New clearXxx() methods reset to null (server default).
  • Internal fields remain nullable boxed types — Jackson serialization is unchanged. @JsonIgnore on Optional-returning getters prevents Jackson from attempting to serialize Optional wrappers.
  • All callers updated from null-check patterns to Optional APIs:
// Before
request.setEnableSessionTelemetry(config.getEnableSessionTelemetry());

// After
config.getEnableSessionTelemetry().ifPresent(request::setEnableSessionTelemetry);

Affected classes (15):

  • Public config: CopilotClientOptions, SessionConfig, ResumeSessionConfig, InfiniteSessionConfig, InputOptions, ModelCapabilitiesOverride.Supports, ModelCapabilitiesOverride.Limits, ProviderConfig, TelemetryConfig, SessionUiCapabilities, CustomAgentConfig, UserInputRequest
  • Wire DTOs: CreateSessionRequest, ResumeSessionRequest, McpServerConfig, ModelLimits

Updated callers: CliServerManager, CopilotClient, CopilotSession, SessionRequestBuilder

Not changed: Records, generated code under src/generated/java/, primitive fields that were already non-nullable.

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • mvn spotless:apply has been run to format the code
  • mvn clean verify passes locally

Does this introduce a breaking change?

  • Yes
  • No

Getter return types change from Boolean/Integer/DoubleOptional<Boolean>/OptionalInt/OptionalDouble. Setter parameter types change from boxed → primitive. Callers passing null to setters must use the new clearXxx() methods instead.


Copilot AI and others added 2 commits May 12, 2026 00:33
…ves in public API

Change getter return types from nullable Boolean/Integer/Double to
Optional<Boolean>/OptionalInt/OptionalDouble on all mutable config/builder
classes. Setters now take primitive parameters. Add clearXxx() methods
for resetting to null (server default). Add @JsonIgnore on Optional-returning
getters to preserve Jackson serialization. Update all callers and tests.

Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Co-authored-by: edburns <75821+edburns@users.noreply.github.com>
Copilot AI changed the title [WIP] Update public API to use Optional return types refactor: use Optional return types instead of nullable boxed primitives in public API May 12, 2026
Copilot AI requested a review from edburns May 12, 2026 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Optional return types instead of nullable boxed primitives in public API

2 participants