Skip to content

Conversation

@hgh1472
Copy link
Contributor

@hgh1472 hgh1472 commented Jun 1, 2025

While reading through the code, I found the method name to be somewhat
ambiguous and not fully descriptive of its purpose.

So I renamed the method to make its purpose clearer and more
self-explanatory. If there was another reason for the original naming,
I’d be happy to hear about it.

Reviewers: Lianet Magrans lmagrans@confluent.io

@github-actions github-actions bot added triage PRs from the community consumer clients small Small PRs labels Jun 1, 2025
@lianetm lianetm removed the triage PRs from the community label Jun 4, 2025
@lianetm
Copy link
Member

lianetm commented Jun 4, 2025

Hi @hgh1472 , thanks for the patch! I guess the naming came from the fact that this throws only under a certain condition (if the group id is empty), therefore "maybeThrow...", makes sense?

That being said, we can surely improve readability like you're suggesting, but being explicit about the condition I would say (otherwise I don't see much gain between maybeThrow vs throwIf). So something like throwIfGroupIdEmpty maybe?

Also, we should change consistently on the AsyncKafkaConsumer I would expect. Thanks!

@hgh1472
Copy link
Contributor Author

hgh1472 commented Jun 5, 2025

@lianetm Thanks for the reply!
I completely agree with your points. My intention was to clearly reflect the specific condition you mentioned.
If you agree with renaming the method, would it be okay for me to proceed with updating AsyncKafkaConsumer accordingly, as mentioned?

@hgh1472
Copy link
Contributor Author

hgh1472 commented Jun 5, 2025

@lianetm
I've completed the changes as suggested!
I think throwIfGroupIdEmpty is the most appropriate name.

@lianetm
Copy link
Member

lianetm commented Jun 5, 2025

Thanks for the update! Just a nit, throwIfGroupIdNotDefined or similar is probably the accurate one. The validation for empty group ID happens first, at a higher level in the constructor

throw new InvalidGroupIdException("The configured " + ConsumerConfig.GROUP_ID_CONFIG
, and then we have some APIs that require group Id (so they throwIfGroupIdNotDefined)
(Sorry I suggested the empty myself initially, mixing empty optional vs empty string)

@hgh1472
Copy link
Contributor Author

hgh1472 commented Jun 6, 2025

@lianetm
Would it be correct to understand your point as saying that throwIfGroupIdEmpty could be confusing because the term “empty” overlaps with both Optional.empty() and an empty String?
In other words, the method is essentially checking whether the groupId is defined or not — is that right?

@lianetm
Copy link
Member

lianetm commented Jun 6, 2025

the method is essentially checking whether the groupId is defined or not — is that right?

exactly, it's checking that it's defined because those APIs require a groupId (and if it's defined we know already it will be non-empty because that's enforced in the consumer constructor)

@hgh1472
Copy link
Contributor Author

hgh1472 commented Jun 6, 2025

@lianetm
thanks for catching a detail I could have missed!
I updated the method name accordingly to reflect your feedback.

Copy link
Member

@lianetm lianetm left a comment

Choose a reason for hiding this comment

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

Thanks for the improvement @hgh1472! LGTM

@lianetm lianetm merged commit c4a769b into apache:trunk Jun 6, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants