Skip to content

Fix potential NullPointerException for Kafka headers with null value #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

javabrett
Copy link
Contributor

In Kafka Connect, a message Header value can be null, so additional null-checks are required when processing header values e.g. for the Splunk index, to avoid an NPE in headerId and elsewhere e.g.:

org.apache.kafka.connect.errors.ConnectException: Exiting WorkerSinkTask due to unrecoverable exception.
        at org.apache.kafka.connect.runtime.WorkerSinkTask.deliverMessages(WorkerSinkTask.java:622)
        at org.apache.kafka.connect.runtime.WorkerSinkTask.poll(WorkerSinkTask.java:334)
        at org.apache.kafka.connect.runtime.WorkerSinkTask.iteration(WorkerSinkTask.java:235)
        at org.apache.kafka.connect.runtime.WorkerSinkTask.execute(WorkerSinkTask.java:204)
        at org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:201)
        at org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:256)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.apache.kafka.connect.header.Header.value()" is null
        at com.splunk.kafka.connect.SplunkSinkTask.headerId(SplunkSinkTask.java:226)
        at com.splunk.kafka.connect.SplunkSinkTask.handleRecordsWithHeader(SplunkSinkTask.java:190)
        at com.splunk.kafka.connect.SplunkSinkTask.handleRaw(SplunkSinkTask.java:170)
        at com.splunk.kafka.connect.SplunkSinkTask.put(SplunkSinkTask.java:110)
        at org.apache.kafka.connect.runtime.WorkerSinkTask.deliverMessages(WorkerSinkTask.java:588)
        ... 10 more

Adds a failing -> passing test, when operating in HEC raw mode, with header support enabled.

In Connect, a message Header can be null, so additional null-checks are
required when processing header values e.g. for the Splunk index, to
avoid an NPE.

Adds a failing -> passing test.
@javabrett javabrett temporarily deployed to workflow-approval October 10, 2023 22:35 — with GitHub Actions Inactive
@VihasMakwana VihasMakwana self-requested a review October 16, 2023 20:05
Copy link
Contributor

@VihasMakwana VihasMakwana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice catch.
Will merge once CI is green.

@github-actions
Copy link

Unit Test Results

164 tests  +1   164 ✔️ +1   38s ⏱️ ±0s
  23 suites ±0       0 💤 ±0 
  23 files   ±0       0 ±0 

Results for commit 4528b17. ± Comparison against base commit 9475fad.

@javabrett
Copy link
Contributor Author

Thanks @VihasMakwana - just checking, does this PR generate a CI fail, or would that be on the parent commit/branch ... should I rebase to a different parent commit perhaps?

@VihasMakwana
Copy link
Contributor

I think this is because of some issue with requirements, not with your changes. I will merge and try to resolve it. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants