Skip to content

Commit

Permalink
MINOR: Fix MockAdminClient to not throw IndexOutOfBoundsException whe…
Browse files Browse the repository at this point in the history
…n brokerId is above the known one. (#8392)

Reviewers: Rajini Sivaram <rajinisivaram@googlemail.com>
  • Loading branch information
dajac committed Mar 31, 2020
1 parent 75e8ee1 commit 121c769
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,12 @@ synchronized public DescribeConfigsResult describeConfigs(Collection<ConfigResou
synchronized private Config getResourceDescription(ConfigResource resource) {
switch (resource.type()) {
case BROKER: {
Map<String, String> map =
brokerConfigs.get(Integer.valueOf(resource.name()));
if (map == null) {
int brokerId = Integer.valueOf(resource.name());
if (brokerId >= brokerConfigs.size()) {
throw new InvalidRequestException("Broker " + resource.name() +
" not found.");
}
return toConfigObject(map);
return toConfigObject(brokerConfigs.get(brokerId));
}
case TOPIC: {
TopicMetadata topicMetadata = allTopics.get(resource.name());
Expand Down Expand Up @@ -538,11 +537,10 @@ synchronized private Throwable handleIncrementalResourceAlteration(
} catch (NumberFormatException e) {
return e;
}
Map<String, String> map = brokerConfigs.get(brokerId);
if (map == null) {
if (brokerId >= brokerConfigs.size()) {
return new InvalidRequestException("no such broker as " + brokerId);
}
HashMap<String, String> newMap = new HashMap<>(map);
HashMap<String, String> newMap = new HashMap<>(brokerConfigs.get(brokerId));
for (AlterConfigOp op : ops) {
switch (op.opType()) {
case SET:
Expand Down

0 comments on commit 121c769

Please sign in to comment.