Skip to content

Commit 3f514b0

Browse files
authored
validateNonWorkflowInvocation (#393)
Validate invocation capture is not enabled when invoking a non @workflow method via DBOS Invocation handler Note, using more generic terminology because #390 extends invocation capture to debouncer in addition to startWorkflow Fixes #376
1 parent f226fb8 commit 3f514b0

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

transact/src/main/java/dev/dbos/transact/execution/DBOSExecutor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,14 @@ private <T, E extends Exception> T runStepInternal(
11441144

11451145
// Workflow Execution Methods
11461146

1147+
// helper method to validate that @Workflow methods are not invoked from the startWorkflow lambda
1148+
public void validateNonWorkflowInvocation() {
1149+
var hook = hookHolder.get();
1150+
if (hook != null) {
1151+
throw new RuntimeException("Only @Workflow functions may run in this context");
1152+
}
1153+
}
1154+
11471155
// execute a workflow via a proxy
11481156
public Object runWorkflow(
11491157
Object target, String instanceName, Method method, Object[] args, Workflow wfTag)

transact/src/main/java/dev/dbos/transact/internal/DBOSInvocationHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Exceptio
5757
var implMethod = target.getClass().getMethod(method.getName(), method.getParameterTypes());
5858
implMethod.setAccessible(true);
5959

60+
var executor = executor();
6061
var wfTag = implMethod.getAnnotation(Workflow.class);
6162
if (wfTag != null) {
62-
return executor().runWorkflow(target, instanceName, implMethod, args, wfTag);
63+
return executor.runWorkflow(target, instanceName, implMethod, args, wfTag);
6364
}
6465

66+
executor.validateNonWorkflowInvocation();
67+
6568
var stepTag = implMethod.getAnnotation(Step.class);
6669
if (stepTag != null) {
6770
var options = StepOptions.create(stepTag, method);
68-
return executor().runStep(() -> implMethod.invoke(target, args), options, null);
71+
return executor.runStep(() -> implMethod.invoke(target, args), options, null);
6972
}
7073

7174
return method.invoke(target, args);

0 commit comments

Comments
 (0)