temporalio / sdk-java

Temporal Java SDK
https://temporal.io
Apache License 2.0
208 stars 141 forks source link

ParameterizedTypeImpl class cast exception #1056

Open geirhoe opened 2 years ago

geirhoe commented 2 years ago

When starting a workflow, the worker using temporal-sdk 1.6.0 fails with the following error

13:34:33.608 [Workflow Executor taskQueue="test-queue", namespace="pmdi.o11n.test-namespace": 4] ERROR i.t.internal.worker.PollerOptions - uncaught exception java.lang.RuntimeException: Failure processing workflow task. WorkflowId=3dfcaab2-7d2d-4b75-b013-abdea39bdf10, RunId=c5d10d3e-a77a-49dc-ae0d-1e09d25d842f, Attempt=3 at io.temporal.internal.worker.WorkflowWorker$TaskHandlerImpl.wrapFailure(WorkflowWorker.java:297) at io.temporal.internal.worker.WorkflowWorker$TaskHandlerImpl.wrapFailure(WorkflowWorker.java:195) at io.temporal.internal.worker.PollTaskExecutor.lambda$process$0(PollTaskExecutor.java:79) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: io.temporal.internal.replay.InternalWorkflowTaskException: Failure handling event 6 of type 'EVENT_TYPE_WORKFLOW_TASK_STARTED' during execution. {PreviousStartedEventId=6, workflowTaskStartedEventId=6, Currently Processing StartedEventId=6} at io.temporal.internal.statemachines.WorkflowStateMachines.createEventProcessingException(WorkflowStateMachines.java:223) at io.temporal.internal.statemachines.WorkflowStateMachines.handleEventsBatch(WorkflowStateMachines.java:202) at io.temporal.internal.statemachines.WorkflowStateMachines.handleEvent(WorkflowStateMachines.java:176) at io.temporal.internal.replay.ReplayWorkflowRunTaskHandler.handleWorkflowTaskImpl(ReplayWorkflowRunTaskHandler.java:176) at io.temporal.internal.replay.ReplayWorkflowRunTaskHandler.handleWorkflowTask(ReplayWorkflowRunTaskHandler.java:145) at io.temporal.internal.replay.ReplayWorkflowTaskHandler.handleWorkflowTaskWithQuery(ReplayWorkflowTaskHandler.java:122) at io.temporal.internal.replay.ReplayWorkflowTaskHandler.handleWorkflowTask(ReplayWorkflowTaskHandler.java:97) at io.temporal.internal.worker.WorkflowWorker$TaskHandlerImpl.handle(WorkflowWorker.java:237) at io.temporal.internal.worker.WorkflowWorker$TaskHandlerImpl.handle(WorkflowWorker.java:195) at io.temporal.internal.worker.PollTaskExecutor.lambda$process$0(PollTaskExecutor.java:73) ... 3 common frames omitted Caused by: java.lang.RuntimeException: WorkflowTask: failure executing SCHEDULED->WORKFLOW_TASK_STARTED, transition history is [CREATED->WORKFLOW_TASK_SCHEDULED] at io.temporal.internal.statemachines.StateMachine.executeTransition(StateMachine.java:151) at io.temporal.internal.statemachines.StateMachine.handleHistoryEvent(StateMachine.java:101) at io.temporal.internal.statemachines.EntityStateMachineBase.handleEvent(EntityStateMachineBase.java:67) at io.temporal.internal.statemachines.WorkflowStateMachines.handleSingleEvent(WorkflowStateMachines.java:236) at io.temporal.internal.statemachines.WorkflowStateMachines.handleEventsBatch(WorkflowStateMachines.java:200) ... 11 common frames omitted Caused by: java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl and java.lang.Class are in module java.base of loader 'bootstrap') at io.temporal.common.converter.DataConverter.arrayFromPayloads(DataConverter.java:92) at io.temporal.internal.sync.POJOWorkflowImplementationFactory$POJOWorkflowImplementation.execute(POJOWorkflowImplementationFactory.java:285) at io.temporal.internal.sync.WorkflowExecuteRunnable.run(WorkflowExecuteRunnable.java:72) at io.temporal.internal.sync.SyncWorkflow.lambda$start$0(SyncWorkflow.java:137) at io.temporal.internal.sync.CancellationScopeImpl.run(CancellationScopeImpl.java:101) at io.temporal.internal.sync.WorkflowThreadImpl$RunnableWrapper.run(WorkflowThreadImpl.java:111) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ... 3 common frames omitted

I have created a small sample project that shows the error, please give me an email adress I can send it to

Spikhalskiy commented 2 years ago

@geirhoe feel free to send the reproduction to dmitry@temporal.io

geirhoe commented 2 years ago

This is caused by user error.

The workflow expects a map, and none is provided by the start workflow command. Using this start command, the worker works without error:

tctl --namespace pmdi.o11n.test-namespace workflow start --taskqueue test-queue --workflow_type LogVarsWorkflow --input '{"test":"test"}'

Perhaps she sdk should report this a an error instead of causing this stack trace ?

Spikhalskiy commented 2 years ago

I agree that this stacktrace is cryptic and doesn't communicate the underlying reason clearly. I will take a look into improving this.

josh-berry commented 8 months ago

Not sure if this is still an issue since this was reported quite some time ago. Sounds like the actual issue here is: when an invalid (non-map-shaped) input is provided to a workflow, the reported stack trace is confusing. Is that a fair summary?

Do we know if this is still an issue in recent Java SDKs?