Skip to content

Commit 16bd172

Browse files
committed
fix: Make tenant optional in MessageSendParams
The `tenant` field in `MessageSendParams` was previously required and validated as non-null in the compact constructor, which forced callers to always provide a tenant even when it is not applicable. This change makes `tenant` truly optional: - Remove `Assert.checkNotNullParam("tenant", tenant)` from the compact constructor so that null values are accepted at construction time - Annotate the `tenant` record component with `@Nullable` to clearly signal that null may be passed by callers - Normalize null tenant to an empty string in the compact constructor, which is the single point of normalization for all construction paths - Update `Builder.tenant()` to accept a `@Nullable String` so that callers can explicitly pass null without a type violation - Simplify `Builder.build()` to pass `tenant` directly, delegating normalization to the compact constructor Javadoc is updated across the class to accurately reflect the optional nature, default value, and normalization behavior of `tenant`. Fixes: #693
1 parent c595071 commit 16bd172

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

spec/src/main/java/io/a2a/spec/MessageSendParams.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,25 @@
1717
* @param message the message to send to the agent (required)
1818
* @param configuration optional configuration for message processing behavior
1919
* @param metadata optional arbitrary key-value metadata for the request
20-
* @param tenant optional tenant, provided as a path parameter.
20+
* @param tenant optional tenant identifier provided as a path parameter; defaults to empty string if not specified
2121
* @see MessageSendConfiguration for available configuration options
2222
* @see <a href="https://a2a-protocol.org/latest/">A2A Protocol Specification</a>
2323
*/
2424
public record MessageSendParams(Message message, @Nullable MessageSendConfiguration configuration,
25-
@Nullable Map<String, Object> metadata, String tenant) {
25+
@Nullable Map<String, Object> metadata, @Nullable String tenant) {
2626

2727
/**
28-
* Compact constructor for validation.
29-
* Validates that required parameters are not null.
30-
*
31-
* @param message the message to send
32-
* @param configuration optional message send configuration
33-
* @param metadata optional metadata
34-
* @param tenant the tenant identifier
28+
* Compact constructor for validation and normalization.
29+
* Validates that {@code message} is not null and normalizes
30+
* {@code tenant} to an empty string if null.
3531
*/
3632
public MessageSendParams {
3733
Assert.checkNotNullParam("message", message);
38-
Assert.checkNotNullParam("tenant", tenant);
34+
tenant = tenant == null ? "" : tenant;
3935
}
4036

4137
/**
42-
* Convenience constructor with default tenant.
38+
* Convenience constructor that sets tenant to empty string by default.
4339
*
4440
* @param message the message to send (required)
4541
* @param configuration optional configuration for message processing
@@ -50,9 +46,9 @@ public MessageSendParams(Message message, @Nullable MessageSendConfiguration con
5046
}
5147

5248
/**
53-
* Create a new Builder
49+
* Creates a new {@link Builder} for constructing {@link MessageSendParams}.
5450
*
55-
* @return the builder
51+
* @return a new builder instance
5652
*/
5753
public static Builder builder() {
5854
return new Builder();
@@ -112,10 +108,10 @@ public Builder metadata(@Nullable Map<String, Object> metadata) {
112108
/**
113109
* Sets optional tenant for the request.
114110
*
115-
* @param tenant arbitrary key-value metadata
111+
* @param tenant optional tenant identifier
116112
* @return this builder
117113
*/
118-
public Builder tenant(String tenant) {
114+
public Builder tenant(@Nullable String tenant) {
119115
this.tenant = tenant;
120116
return this;
121117
}
@@ -131,7 +127,7 @@ public MessageSendParams build() {
131127
Assert.checkNotNullParam("message", message),
132128
configuration,
133129
metadata,
134-
tenant == null ? "" : tenant);
130+
tenant);
135131
}
136132
}
137133
}

0 commit comments

Comments
 (0)