zahed1994 opened a new pull request, #58133:
URL: https://github.com/apache/spark/pull/58133

   ### What changes were proposed in this pull request?
   
   This PR fixes a `NullPointerException` in `KafkaMicroBatchStream.metrics()` 
during Kafka micro-batch streaming progress reporting (`finishTrigger`).
   
   Specifically, `KafkaMicroBatchStream.metrics()` checked 
`latestAvailablePartitionOffsets.isDefined` before extracting partition 
offsets. If `latestAvailablePartitionOffsets` was `Some(null)`, `isDefined` 
returned `true`, causing `latestAvailablePartitionOffsets.get` to return `null` 
and throwing a `NullPointerException` when `.map()` was invoked on it.
   
   This PR updates the condition to `latestAvailablePartitionOffsets.exists(_ 
!= null)` to safely ensure partition offsets are non-null before invoking 
`.map()`.
   
   ### Why are the changes needed?
   
   When uninitialized partition offsets or race conditions occur during 
progress reporting (`finishTrigger`), `latestAvailablePartitionOffsets` can be 
`Some(null)`. Without this check, calling `.map()` on `null` throws a 
`NullPointerException`, crashing the entire streaming query job in production 
after batch execution.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No API changes. Fixes a `NullPointerException` in progress reporting metrics.
   
   ### How was this patch tested?
   
   Added unit test assertion in `KafkaMicroBatchSourceSuite`.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   No.
   


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to