exceptionfactory commented on code in PR #11211:
URL: https://github.com/apache/nifi/pull/11211#discussion_r3253364864


##########
nifi-extension-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/kinesis/firehose/PutKinesisFirehose.java:
##########
@@ -134,8 +134,13 @@ public void onTrigger(final ProcessContext context, final 
ProcessSession session
             for (final FlowFile flowFile : flowFiles) {
                 final String firehoseStreamName = 
context.getProperty(KINESIS_FIREHOSE_DELIVERY_STREAM_NAME).evaluateAttributeExpressions(flowFile).getValue();
 
-                recordHash.computeIfAbsent(firehoseStreamName, k -> new 
ArrayList<>());
-                session.read(flowFile, in -> 
recordHash.get(firehoseStreamName).add(Record.builder().data(SdkBytes.fromInputStream(in)).build()));
+                // Use a single computeIfAbsent().add() call so the list 
lookup is atomic.
+                // The previous two-step pattern (computeIfAbsent then a 
separate get()) could
+                // throw NullPointerException when firehoseStreamName 
evaluates to null via
+                // expression language, because get(null) returned null after 
the absent-key
+                // entry was never actually inserted. (NIFI-14472)
+                session.read(flowFile, in -> 
recordHash.computeIfAbsent(firehoseStreamName, k -> new ArrayList<>())
+                        
.add(Record.builder().data(SdkBytes.fromInputStream(in)).build()));

Review Comment:
   Commenting on the previous behavior is unnecessary and should be removed. In 
addition, it would be helpful to separate the callback implementation across 
multiple lines for readability.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to