Skip to content

MINOR: Resolve hidden NPE in RequestQuotaTest#21587

Merged
AndrewJSchofield merged 1 commit intoapache:trunkfrom
AndrewJSchofield:request-quota-test
Feb 26, 2026
Merged

MINOR: Resolve hidden NPE in RequestQuotaTest#21587
AndrewJSchofield merged 1 commit intoapache:trunkfrom
AndrewJSchofield:request-quota-test

Conversation

@AndrewJSchofield
Copy link
Copy Markdown
Member

@AndrewJSchofield AndrewJSchofield commented Feb 26, 2026

RequestQuotaTest was silently experiencing NPE when testing
SHARE_ACKNOWLEDGE. This is because the default for the group ID in
this request is null, even though this is never actually used in
practice by a real client. The construction of
ShareAcknowledgeRequestData in this test did not initialize a specific
value for group ID, and this means it was left as null. The result was
an NPE handling the request in the broker, which was not the intended
action of the test.

The PR explicitly handles null for group ID and member ID in
SHARE_FETCH and SHARE_ACKNOWLEDGE requests so that we are not
relying on the overall exception handling for this situation. In
practice, this would not be necessary for a real client, but the
defensive code makes sense for this test (or a poorly written client).
It also initialises the request in the test case with a non-null group
ID and member ID for SHARE_ACKNOWLEDGE which aligns with what already
exists for SHARE_FETCH.

Reviewers: Apoorv Mittal apoorvmittal10@gmail.com, Chia-Ping Tsai
chia7712@gmail.com

@github-actions github-actions Bot added core Kafka Broker small Small PRs labels Feb 26, 2026
Copy link
Copy Markdown
Contributor

@apoorvmittal10 apoorvmittal10 left a comment

Choose a reason for hiding this comment

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

LGTM!

Maybe we want to consider to change the ShareAcknowledge RPC json to have groupId as non-nullable in subsequent PR.


val groupId = shareFetchRequest.data.groupId

if (groupId == null) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is interesting. I assumed the null check would be handled by the RPC layer, but it isn't. @AndrewJSchofield could you share some context on this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The NPE occurs in the authorizer. As mentioned, doesn't happen with a real client because group.id must be set in the consumer application config.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@AndrewJSchofield thanks for response

Maybe we want to consider to change the ShareAcknowledge RPC json to have groupId as non-nullable in subsequent PR.

+1

@AndrewJSchofield AndrewJSchofield merged commit 84f810e into apache:trunk Feb 26, 2026
31 checks passed
@AndrewJSchofield AndrewJSchofield deleted the request-quota-test branch February 26, 2026 14:02
Shekharrajak pushed a commit to Shekharrajak/kafka that referenced this pull request Mar 31, 2026
`RequestQuotaTest` was silently experiencing NPE when testing
`SHARE_ACKNOWLEDGE`. This is because the default for the group ID in
this request is null, even though this is never actually used in
practice by a real client. The construction of
`ShareAcknowledgeRequestData` in this test did not initialize a specific
value for group ID, and this means it was left as null. The result was
an NPE handling the request in the broker, which was not the intended
action of the test.

The PR explicitly handles null for group ID and member ID in
`SHARE_FETCH` and `SHARE_ACKNOWLEDGE` requests so that we are not
relying on the overall exception handling for this situation. In
practice, this would not be necessary for a real client, but the
defensive code makes sense for this test (or a poorly written client).
It also initialises the request in the test case with a non-null group
ID and member ID for `SHARE_ACKNOWLEDGE` which aligns with what already
exists for `SHARE_FETCH`.

Reviewers: Apoorv Mittal <apoorvmittal10@gmail.com>, Chia-Ping Tsai
 <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-approved core Kafka Broker KIP-932 Queues for Kafka small Small PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants