Skip to content

[Bug]: MessageSendParams#tenant is documented as optional but enforces a non-null check in the constructor #693

Closed

Description

@CokeLee777

What happened?

The Javadoc for MessageSendParams documents the tenant parameter as optional:

// MessageSendParams.java:20
@param tenant optional tenant, provided as a path parameter.

However, the compact constructor enforces a non-null check on tenant:

// MessageSendParams.java:36-39
public MessageSendParams {
    Assert.checkNotNullParam("message", message);
    Assert.checkNotNullParam("tenant", tenant);  // ← null check despite being documented as optional
}

Additionally, while configuration and metadata are annotated with @Nullable in the record declaration, tenant is not:

// MessageSendParams.java:24-25
public record MessageSendParams(Message message, @Nullable MessageSendConfiguration configuration,
                                @Nullable Map<String, Object> metadata, String tenant) {

This is inconsistent with the inner Builder class, which declares @Nullable String tenant and handles null gracefully by substituting an empty string in build().

Expected behavior

Since tenant is documented as optional, passing null should be permitted. The record declaration should include @Nullable on tenant, and the null check in the compact constructor should be removed.

Relevant log output

``
java.lang.IllegalArgumentException: WFLYUTIL0097: Method parameter 'tenant' cannot be null
    at io.a2a.util.Assert.checkNotNullParam(Assert.java:...)
    at io.a2a.spec.MessageSendParams.<init>(MessageSendParams.java:38)


## Relevant files

- `spec/src/main/java/io/a2a/spec/MessageSendParams.java` — lines 20, 25, 38

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added theissue type on Mar 1, 2026
  2. CokeLee777 commented on Mar 1, 2026

    @CokeLee777
    ContributorAuthor

    I'll work on a fix for this and open a PR.

  3. added 5 commits that reference this issue on Mar 1, 2026
    5ae5de9
    e0f782d
    eb59d5f
    47bc184
    16bd172
  4. ehsavoie commented on Mar 2, 2026

    @ehsavoie
    Collaborator

    It should be an empty string, the builder enforces that.

  5. ehsavoie commented on Mar 2, 2026

    @ehsavoie
    Collaborator

    I think this is wrong: the tenant is a path parameter where "" does make sense. Having something that can be null requires testing at each usage. Also the same pattern is repeated across all the source code. So I disagree with this being a bug.

  6. CokeLee777 commented on Mar 2, 2026

    @CokeLee777
    ContributorAuthor

    @ehsavoie
    Thanks for the review. I understand that the constructor-level null check is intentional for programmatic construction paths.

    The issue I'm facing is specifically during Gson deserialization. When using JsonUtil.fromJson(body, SendMessageRequest.class), Gson recursively deserializes the inner MessageSendParams field as well. If the incoming JSON payload doesn't contain a tenant field in params, Gson sets it to null via reflection — bypassing the Builder and the 3-arg constructor that default it to "". This means SendMessageRequest itself becomes unparseable through JsonUtil whenever tenant is absent from the JSON, which is the standard case when the client sends a message via A2A.toUserMessage() + client.sendMessage(), since neither of those APIs sets a tenant value.

    Would you be open to an alternative approach, such as registering a custom Gson TypeAdapter for MessageSendParams in JsonUtil that normalizes a null tenant to "" before passing it to the constructor? This way, the constructor's null check remains intact for all programmatic paths while keeping SendMessageRequest deserializable via the SDK's own JsonUtil.

    Alternatively, is there a recommended way to set the tenant on the client side before sending a message?

  7. ehsavoie commented on Mar 3, 2026

    @ehsavoie
    Collaborator

    I agree that something is missing there even if you use
    sendMessage(@NonNull MessageSendParams params, @NonNull List<BiConsumer<ClientEvent, AgentCard>> consumers, @Nullable Consumer<Throwable> streamingErrorHandler, @Nullable ClientCallContext context) throws A2AClientException;
    you can set the tenant on the params here.
    I'm wondering if we could use the ClientCallContext to pass on the tenant or if we should provide another set of methods

  8. CokeLee777 commented on Mar 3, 2026

    @CokeLee777
    ContributorAuthor

    Thank you for the review and the discussion! I'll close #694 for now and take more time to think about a better approach that addresses the design more fundamentally. If anyone has ideas on the best way to handle this, please feel free to share in the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions