From c2df718c0f30f0cc7f8950e1e8c1977d8e4ea04b Mon Sep 17 00:00:00 2001 From: Carl Zogheib <11421173+carlzogh@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:01:36 +0100 Subject: [PATCH] Fix NPE when UserIdentity is null --- .../dynamodb/DynamodbRecordTransformer.java | 4 +++- .../dynamodb/DynamodbRecordTransformerTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java index d9547a76..4f93ca20 100644 --- a/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java +++ b/aws-lambda-java-events-sdk-transformer/src/main/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformer.java @@ -16,7 +16,9 @@ public static Record toRecordV2(final DynamodbEvent.DynamodbStreamRecord record) .eventSource(record.getEventSource()) .eventVersion(record.getEventVersion()) .userIdentity( - DynamodbIdentityTransformer.toIdentityV2(record.getUserIdentity()) + record.getUserIdentity() != null + ? DynamodbIdentityTransformer.toIdentityV2(record.getUserIdentity()) + : null ) .build(); } diff --git a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java index 69645844..3218a856 100644 --- a/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java +++ b/aws-lambda-java-events-sdk-transformer/src/test/java/com/amazonaws/services/lambda/runtime/events/transformers/dynamodb/DynamodbRecordTransformerTest.java @@ -50,4 +50,14 @@ public void testToRecordV2() { Assertions.assertEquals(record_v2, convertedRecord); } + @Test + public void testToRecordV2WhenUserIdentityIsNull() { + DynamodbEvent.DynamodbStreamRecord record = record_event.clone(); + record.setUserIdentity(null); + + Assertions.assertDoesNotThrow(() -> { + DynamodbRecordTransformer.toRecordV2(record); + }); + } + } \ No newline at end of file