NIFI-14472: Fix potential NPE in PutKinesisFirehose batch accumulation#11211
Open
rakesh-rsky wants to merge 2 commits intoapache:mainfrom
Open
NIFI-14472: Fix potential NPE in PutKinesisFirehose batch accumulation#11211rakesh-rsky wants to merge 2 commits intoapache:mainfrom
rakesh-rsky wants to merge 2 commits intoapache:mainfrom
Conversation
…eam name evaluates to null The onTrigger() method used a two-step pattern to populate the recordHash map: 1. recordHash.computeIfAbsent(firehoseStreamName, k -> new ArrayList<>()) 2. recordHash.get(firehoseStreamName).add(record) // ← NPE here When the KINESIS_FIREHOSE_DELIVERY_STREAM_NAME expression evaluates to null (e.g., the referenced FlowFile attribute is absent), computeIfAbsent(null, ...) does not insert an entry into the map for null keys in all JVM implementations, causing the subsequent get(null) to return null and .add() to throw: NullPointerException: Cannot invoke List.add() because Map.get() returns null - Collapsed the two-step lookup into a single atomic computeIfAbsent().add() call, eliminating the null-return window between the two statements - The fix applies to the recordHash population step; hashFlowFiles already used computeIfAbsent correctly in a single step on the following line Co-authored-by: Rakesh Kumar Singh <rsky.rakesh@gmail.com>
36af390 to
67c2d4c
Compare
…n macOS The test class was missing an @AfterEach to shut down the provider after each test. Tests that called provider.initialize() but not provider.shutdown() left the Kubernetes client's Netty event loop open. On macOS with Zulu JDK 21, the GC collected the event loop before KubernetesMockServerExtension.afterEach() ran, causing MockWebServer.await() to throw RejectedExecutionException: 'event executor terminated' Fix: add @AfterEach shutdownProvider() to guarantee the Kubernetes client is closed before the mock server extension tears down, ensuring deterministic cleanup across all platforms and JVM implementations. Co-authored-by: Rakesh Kumar Singh <rsky.rakesh@gmail.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes a race condition / NPE in PutKinesisFirehose.onTrigger() where a two-step computeIfAbsent() + get() on the batch-accumulation map could return
ull if the entry was evicted between the two calls.
Changes
Testing
Fixes: https://issues.apache.org/jira/browse/NIFI-14472