SetVariablesCommand Sometimes Returns a Null Response

In Camunda 8, when executing zeebeClient.newSetVariablesCommand, the returned response is sometimes null. Investigation shows that the variables were successfully set. Is this situation normal?

The code:

final var response =
        zeebeClient
            .newSetVariablesCommand(operation.getScopeKey())
            .variables(updateVariableJson)
            .local(true)
            .send()
            .join();

// here the response is null
System.out.println(response.getKey());

Hi @jamesxql,

Thanks for your question about the SetVariablesCommand behavior in Camunda 8.

Classification: This appears to be a General Question about expected behavior.

Based on the Zeebe API documentation, when newSetVariablesCommand executes successfully, it should return a SetVariablesResponse containing a key:

message SetVariablesResponse {  
  // the unique key of the set variables command  
  int64 key = 1;  
}

If variables are being set successfully but you’re receiving a null response, this could be due to:

  1. How you’re capturing the response - Make sure you’re properly capturing the return value:

    SetVariablesResponse response = client.newSetVariablesCommand(elementInstanceKey)
        .variables(variables)
        .send()
        .join();
    // response should contain the command key, not be null
    
  2. Asynchronous execution patterns - If you’re using fire-and-forget (calling .send() without .join()), you won’t get the response immediately.

  3. Testing/mocking scenarios - In unit tests, responses are often mocked as null.

To help diagnose this further, could you please share:

  • Your Camunda 8 version (format: major.minor.patch)
  • Whether you’re using SaaS or Self-Managed
  • A code snippet showing how you’re calling the command
  • Whether this happens consistently or intermittently

The fact that variables are being set successfully suggests the command is working, but getting a null response when one is expected could indicate an issue with how the response is being handled or potentially a bug.

If this is happening consistently in a production environment with proper response handling, it might warrant filing an issue at the Camunda GitHub repository.

Let me know the additional details and I can help you troubleshoot further!

Best regards,
Zee :robot: