-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-8240: Fix NPE in Source.equals() #6589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67f8f8b
ebde0b9
1e44568
33b9e3a
ea3e498
ff0e74e
5f2a96e
ff1c570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,7 +282,7 @@ private boolean isMatch(final String topic) { | |
|
|
||
| @Override | ||
| Source describe() { | ||
| return new Source(name, new HashSet<>(topics), pattern); | ||
| return new Source(name, topics.size() == 0 ? null : new HashSet<>(topics), pattern); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1281,6 +1281,9 @@ private static class NodeComparator implements Comparator<TopologyDescription.No | |
| @Override | ||
| public int compare(final TopologyDescription.Node node1, | ||
| final TopologyDescription.Node node2) { | ||
| if (node1.equals(node2)) { | ||
| return 0; | ||
| } | ||
| final int size1 = ((AbstractNode) node1).size; | ||
| final int size2 = ((AbstractNode) node2).size; | ||
|
|
||
|
|
@@ -1399,6 +1402,7 @@ public abstract static class AbstractNode implements TopologyDescription.Node { | |
| int size; | ||
|
|
||
| AbstractNode(final String name) { | ||
| Objects.requireNonNull(name, "name cannot be null"); | ||
| this.name = name; | ||
| this.size = 1; | ||
| } | ||
|
|
@@ -1435,6 +1439,13 @@ public Source(final String name, | |
| final Set<String> topics, | ||
| final Pattern pattern) { | ||
| super(name); | ||
| if (topics == null && pattern == null) { | ||
| throw new IllegalArgumentException("Either topics or pattern must be not-null, but both are null."); | ||
| } | ||
| if (topics != null && pattern != null) { | ||
| throw new IllegalArgumentException("Either topics or pattern must be null, but both are not null."); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should happen if the topic or the pattern is empty?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think those are special cases. For
\cc @guozhangwang or @hachikuji to confirm. |
||
| this.topics = topics; | ||
| this.topicPattern = pattern; | ||
| } | ||
|
|
@@ -1479,8 +1490,10 @@ public boolean equals(final Object o) { | |
| final Source source = (Source) o; | ||
| // omit successor to avoid infinite loops | ||
| return name.equals(source.name) | ||
| && topics.equals(source.topics) | ||
| && topicPattern.equals(source.topicPattern); | ||
| && (topics == null && source.topics == null | ||
| || topics != null && topics.equals(source.topics)) | ||
| && (topicPattern == null && source.topicPattern == null | ||
| || topicPattern != null && topicPattern.pattern().equals(source.topicPattern.pattern())); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1709,6 +1722,9 @@ private static class GlobalStoreComparator implements Comparator<TopologyDescrip | |
| @Override | ||
| public int compare(final TopologyDescription.GlobalStore globalStore1, | ||
| final TopologyDescription.GlobalStore globalStore2) { | ||
| if (globalStore1.equals(globalStore2)) { | ||
| return 0; | ||
| } | ||
| return globalStore1.id() - globalStore2.id(); | ||
| } | ||
| } | ||
|
|
@@ -1719,6 +1735,9 @@ private static class SubtopologyComparator implements Comparator<TopologyDescrip | |
| @Override | ||
| public int compare(final TopologyDescription.Subtopology subtopology1, | ||
| final TopologyDescription.Subtopology subtopology2) { | ||
| if (subtopology1.equals(subtopology2)) { | ||
| return 0; | ||
| } | ||
| return subtopology1.id() - subtopology2.id(); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging the issue, I figure that the use comparators don't do deep comparison. This is the corresponding fix. (Similar below)