Skip to content

Commit

Permalink
Fix null pointer exception
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar committed Oct 18, 2024
1 parent 7ca2a07 commit 7b08738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public String visibility() {
@JsonProperty
@Schema(readOnly = true, description = "The number of partitions in this topic")
public Integer numPartitions() {
if (partitions == null) {
return null;
}

return partitions.getOptionalPrimary().map(Collection::size).orElse(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ public CompletionStage<List<Topic>> listTopics(List<String> fields, String offse

Topic tallySummary(Map<String, Integer> statuses, AtomicInteger partitionCount, Topic topic) {
statuses.compute(topic.status(), (k, v) -> v == null ? 1 : v + 1);
partitionCount.addAndGet(topic.getAttributes().numPartitions());

Integer numPartitions = topic.getAttributes().numPartitions();
//numPartitions may be null if it was not included in the requested fields
if (numPartitions != null) {
partitionCount.addAndGet(numPartitions);
}

return topic;
}

Expand Down

0 comments on commit 7b08738

Please sign in to comment.