OutboundConnector Result Handling Logic Improvement Suggestions

In the ConnectorResultHandler.createOutputVariables method, the program checks whether the resultExpression is empty. If it is not empty, it performs mapping for the value of responseContent. However, if responseContent == null, the mapping logic will throw an error: “Failed to evaluate expression ‘=xxxxxxx’ in context, Reason: Context is null.”

It is recommended to check whether the response is null before calling the createOutputVariables method. If it is null, the result set mapping should be skipped, and the method should return directly:

private ConnectorResult getConnectorResult(ActivatedJob job) {
    Duration retryBackoff = null;
    try {
      retryBackoff = getBackoffDuration(job);
      var context =
          new JobHandlerContext(
              job, getSecretProvider(), validationProvider, documentFactory, objectMapper);
      var response = call.execute(context);
      
      if (response == null) {
          return new ConnectorResult.SuccessResult(null, null);
      }
      
      var responseVariables =
          connectorResultHandler.createOutputVariables(
              response,
              job.getCustomHeaders().get(Keywords.RESULT_VARIABLE_KEYWORD),
              job.getCustomHeaders().get(Keywords.RESULT_EXPRESSION_KEYWORD));
      return new ConnectorResult.SuccessResult(response, responseVariables);
    } catch (Exception e) {
      return outboundConnectorExceptionHandler.manageConnectorJobHandlerException(
          e, job, retryBackoff);
    }
  }

Thank you for this detailed analysis and improvement suggestion!

Classification: This appears to be a Feature Request (or potentially a bug report) for improving error handling in the Camunda Connector SDK.

You’ve identified a valid issue where the ConnectorResultHandler.createOutputVariables method can throw a “Context is null” error when:

  1. responseContent is null
  2. resultExpression is not empty
  3. The mapping logic attempts to evaluate the expression against the null context

Your proposed solution to check for null response before calling createOutputVariables makes sense and would provide more graceful error handling.

Next Steps

Since this is an improvement to the Camunda Connector SDK itself, I recommend filing this as an issue in the appropriate GitHub repository:

Repository: https://github.com/camunda/connectors/issues

When creating the issue, please include:

  1. Clear description of the current behavior vs. expected behavior
  2. Your code analysis (which you’ve already provided excellently)
  3. Proposed solution with the code snippet you shared
  4. Use case: Explain when this scenario occurs in practice
  5. Environment details:
    • Camunda version you’re using
    • Whether this is SaaS or Self-Managed

Alternative Workaround

In the meantime, if you’re developing custom connectors, you can work around this by ensuring your connector’s execute method never returns null - always return a valid result object, even if it’s empty:

// Instead of returning null
return new MyConnectorResult(); // or appropriate empty result

Would you like help drafting the GitHub issue, or do you have any questions about this approach?

@jamesxql I’ve filed Don't evaluate result expression on empty body · Issue #5730 · camunda/connectors · GitHub for internal discussion
Please take a look if I have captured your intent correctly