• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

temporalio / sdk-java / #431

18 Nov 2026 09:28PM UTC coverage: 71.813% (+0.01%) from 71.8%
#431

push

github

web-flow
Include inherited fields in service stub options toString (#3152)

* Include inherited fields in service stub options toString

WorkflowServiceStubsOptions.toString rendered only the five fields
declared on the subclass, silently dropping every field inherited from
ServiceStubsOptions. Target, TLS settings, timeouts, and headers were
absent from the output, which is exactly the connection information
wanted when diagnosing a client from logs.

OperatorServiceStubsOptions and CloudServiceStubsOptions had no
toString at all and fell back to Object.toString, logging as an
unreadable identity hash.

Extract the field rendering on ServiceStubsOptions into a
package-private toStringFields helper and have each subclass inline it
alongside its own fields. The helper is package-private because all
four classes live in io.temporal.serviceclient, so this adds no public
API surface.

Also include apiKeyProvided, which already participates in equals and
hashCode but was omitted from toString. The API key itself is held by a
metadata provider and is still never rendered.

Fixes #2148.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Render header names instead of header values in toString

Metadata.toString renders header values in the clear. The previous
commit propagated the inherited headers field into
WorkflowServiceStubsOptions, OperatorServiceStubsOptions, and
CloudServiceStubsOptions, which would have newly exposed any credential
supplied through setHeaders, such as a static Authorization header.

Render the header names only. This keeps the diagnostic signal that
matters when reading the output, whether a header is configured and
which ones, without printing what they contain.

Also add a regression test for the missing separator before
congestionInitialInterval in RpcRetryOptions.toString.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* Add changelog entry for service stub options toString

Co-Authored-By: Claude Opus 5.5 <noreply@anthro... (continued)

8779 of 14371 branches covered (61.09%)

Branch coverage included in aggregate %.

5 of 6 new or added lines in 4 files covered. (83.33%)

892 existing lines in 36 files now uncovered.

34625 of 46069 relevant lines covered (75.16%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.05
/temporal-sdk/src/main/java/io/temporal/internal/sync/ExternalWorkflowInvocationHandler.java
1
package io.temporal.internal.sync;
2

3
import io.temporal.api.common.v1.WorkflowExecution;
4
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
5
import io.temporal.common.metadata.POJOWorkflowInterfaceMetadata;
6
import io.temporal.common.metadata.POJOWorkflowMethodMetadata;
7
import io.temporal.common.metadata.WorkflowMethodType;
8
import io.temporal.internal.common.InternalUtils;
9
import io.temporal.workflow.ExternalWorkflowStub;
10
import io.temporal.workflow.Functions;
11
import java.lang.reflect.InvocationHandler;
12
import java.lang.reflect.Method;
13
import java.util.Objects;
14

15
/** Dynamic implementation of a strongly typed external workflow interface. */
16
public class ExternalWorkflowInvocationHandler implements InvocationHandler {
17

18
  private static final ThreadLocal<ProbeContext> probeContext = new ThreadLocal<>();
1 ✔
19
  private static final ThreadLocal<ProbeResult> probeResult = new ThreadLocal<>();
1 ✔
20

21
  /** Probes one invocation without starting a workflow or sending a signal. */
22
  public static ProbeResult probe(Functions.Proc invocation, WorkflowMethodType expected) {
23
    Objects.requireNonNull(invocation, "invocation");
1 ✔
24
    if (probeContext.get() != null) {
1 ✔
25
      throw new IllegalStateException("Already probing an external workflow invocation");
1 ✔
26
    }
27
    ProbeContext context = new ProbeContext(expected);
1 ✔
28
    probeContext.set(context);
1 ✔
29
    try {
30
      invocation.apply();
1 ✔
31
      ProbeResult result = probeResult.get();
1 ✔
32
      if (context.invocations != 1 || result == null) {
1 !
33
        throw new IllegalArgumentException(
1 ✔
34
            "Expected exactly one external workflow " + expected + " invocation");
35
      }
36
      return result;
1 ✔
37
    } finally {
38
      probeResult.remove();
1 ✔
39
      probeContext.remove();
1 ✔
40
    }
41
  }
42

43
  private static final class ProbeContext {
44
    private final WorkflowMethodType expected;
45
    private int invocations;
46

47
    private ProbeContext(WorkflowMethodType expected) {
1 ✔
48
      this.expected = Objects.requireNonNull(expected, "expected");
1 ✔
49
    }
1 ✔
50
  }
51

52
  /** Metadata captured from a bound external workflow method. */
53
  public static final class ProbeResult {
54
    private final ExternalWorkflowStub stub;
55
    private final Object[] arguments;
56
    private final POJOWorkflowMethodMetadata metadata;
57

58
    private ProbeResult(
59
        ExternalWorkflowStub stub, POJOWorkflowMethodMetadata metadata, Object[] args) {
1 ✔
60
      this.stub = stub;
1 ✔
61
      this.arguments = args == null ? new Object[0] : args.clone();
1 ✔
62
      this.metadata = metadata;
1 ✔
63
    }
1 ✔
64

65
    public ExternalWorkflowStub getStub() {
66
      return stub;
1 ✔
67
    }
68

69
    public Object[] getArguments() {
70
      return arguments.clone();
1 ✔
71
    }
72

73
    public POJOWorkflowMethodMetadata getMetadata() {
74
      return metadata;
1 ✔
75
    }
76
  }
77

78
  private final ExternalWorkflowStub stub;
79
  private final POJOWorkflowInterfaceMetadata workflowMetadata;
80

81
  public ExternalWorkflowInvocationHandler(
82
      Class<?> workflowInterface,
83
      WorkflowExecution execution,
84
      WorkflowOutboundCallsInterceptor workflowOutboundCallsInterceptor,
85
      Functions.Proc1<String> assertReadOnly) {
1 ✔
86
    this.workflowMetadata = POJOWorkflowInterfaceMetadata.newInstance(workflowInterface, false);
1 ✔
87
    this.stub =
1 ✔
88
        new ExternalWorkflowStubImpl(execution, workflowOutboundCallsInterceptor, assertReadOnly);
89
  }
1 ✔
90

91
  @Override
92
  public Object invoke(Object proxy, Method method, Object[] args) {
93
    // Proxy the toString method so the stub can be inspected when debugging.
94
    try {
95
      if (method.equals(Object.class.getMethod("toString"))) {
1 !
UNCOV
96
        return proxyToString();
×
97
      }
UNCOV
98
    } catch (NoSuchMethodException e) {
×
UNCOV
99
      throw new Error("unexpected", e);
×
100
    }
1 ✔
101
    // Implement StubMarker
102
    if (method.getName().equals(StubMarker.GET_UNTYPED_STUB_METHOD)) {
1 ✔
103
      return stub;
1 ✔
104
    }
105
    POJOWorkflowMethodMetadata methodMetadata = workflowMetadata.getMethodMetadata(method);
1 ✔
106
    ProbeContext context = probeContext.get();
1 ✔
107
    if (context != null) {
1 ✔
108
      if (++context.invocations != 1 || methodMetadata.getType() != context.expected) {
1 ✔
109
        throw new IllegalArgumentException(
1 ✔
110
            "Expected exactly one external workflow " + context.expected + " invocation");
1 ✔
111
      }
112
      probeResult.set(new ProbeResult(stub, methodMetadata, args));
1 ✔
113
      return InternalUtils.getValueOrDefault(null, method.getReturnType());
1 ✔
114
    }
115
    switch (methodMetadata.getType()) {
1 !
116
      case QUERY:
UNCOV
117
        throw new UnsupportedOperationException(
×
118
            "Query is not supported from workflow to workflow. "
119
                + "Use activity that perform the query instead.");
120
      case WORKFLOW:
121
        throw new IllegalStateException(
1 ✔
122
            "Cannot start a workflow with an external workflow stub "
123
                + "created through Workflow.newExternalWorkflowStub");
124
      case SIGNAL:
125
        stub.signal(methodMetadata.getName(), args);
1 ✔
126
        break;
1 ✔
127
      case UPDATE:
UNCOV
128
        throw new UnsupportedOperationException(
×
129
            "Cannot update a workflow with an external workflow stub "
130
                + "created through Workflow.newExternalWorkflowStub");
131
      default:
UNCOV
132
        throw new IllegalStateException("unreachable");
×
133
    }
134
    return null;
1 ✔
135
  }
136

137
  private String proxyToString() {
UNCOV
138
    return "ExternalWorkflowProxy{"
×
139
        + "workflowType='"
UNCOV
140
        + workflowMetadata.getWorkflowType().orElse("")
×
141
        + '\''
142
        + ", execution="
UNCOV
143
        + stub.getExecution()
×
144
        + '}';
145
  }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc