Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

[improvement] Remove expensive useless String.format() in canConsumeAsync #1893

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ public CompletableFuture<Boolean> canProduceAsync(KafkaPrincipal principal, Reso

@Override
public CompletableFuture<Boolean> canConsumeAsync(KafkaPrincipal principal, Resource resource) {
checkArgument(resource.getResourceType() == ResourceType.TOPIC,
String.format("Expected resource type is TOPIC, but have [%s]", resource.getResourceType()));
checkArgument(resource.getResourceType() == ResourceType.TOPIC);
Copy link
Member

Choose a reason for hiding this comment

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

Can we extract a method like this: private void checkArgument(ResourceType expected, ResourceType actual)

Copy link
Member

Choose a reason for hiding this comment

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

And we can print the error message in the checkArgument method when the type is unequal.

TopicName topicName = TopicName.get(resource.getName());
return authorizationService.canConsumeAsync(
topicName, principal.getName(), principal.getAuthenticationData(), "");
Expand Down