Handle case where getMemo requests a non-existent key #783
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What was changed
This change causes
Workflow.getMemo
to returnnull
when called with a key that is not present on the memo.The existing
testMemoInWorkflow
test has been modified to test that a missing key passed togetMemo
returnsnull
. It also extends the test to cover when a memo is queried with a mismatched type.A new unit test,
testNoMemoInWorkflowFailsGetMemoGracefully
, has been added to check the case wheregetMemo
returns null for any key when no memo was specified upon starting a workflow.Why?
Workflow.getMemo
currently throws aNullPointerException
when an unknown memo key is requested. Because there's not another way to check for a key's existence before callinggetMemo
, the only way to handle this is to catchNullPointerException
. Checking for null is better for flow control.Checklist
cd temporal-sdk && ../gradlew test --tests io.temporal.workflow.MemoTest