sdk-java icon indicating copy to clipboard operation
sdk-java copied to clipboard

Async activity completion with primitive return value converts null to zero

Open osi opened this issue 5 years ago • 4 comments

Expected Behavior

When using async completion of an activity returning a primitive value and completing with null, a NullPointerException should be generated in either the Workflow or when completing the Activity. (Similar to how auto-unboxing behaves)

Actual Behavior

The workflow has a return value of zero.

Steps to Reproduce the Problem

  1. Create an activity method that returns a primitive, eg long.
  2. Use useLocalManualCompletion to get a completion client
  3. Complete the activity with null, eg complete(null)
  4. Inspect the returned value of the activity in the workflow. It will be zero.

Specifications

  • Version: 0.11.0
  • Platform: using TestWorkflowEnvironment

osi avatar Sep 08 '21 16:09 osi

Hi @osi Would you mind sending a code sample? I couldn't reproduce your issue (see my attempt here) Also, I noticed that your version of SDK is super outdated, I would highly recommend to update.

vkoby avatar Oct 27 '21 16:10 vkoby

@vkoby So, the test in https://github.com/temporalio/sdk-java/pull/846 passes. According to the build status. It shouldn't. This is exactly the problem that is reported in this issue.

Spikhalskiy avatar Oct 27 '21 16:10 Spikhalskiy

@Spikhalskiy @osi , Sorry, I wasn't clear: The reported issue is that null is converted to zero, and the repro step 4 says it's converted to zero. That doesn't reproduce - we are seeing null propagated instead, which if converted to int will result in NPE. There is a separate question whether we want null propagated in these cases, but that's not what that issue is about.

vkoby avatar Oct 27 '21 17:10 vkoby

Yes, I was on an older SDK. The missing detail in the reproduction steps is to invoke the activity synchronously from the workflow, so that there's unboxing required from the null completion value to the local primitive variable.

(yes, this is a programming error in the activity to return null)

osi avatar Oct 27 '21 17:10 osi