Skip to content

Commit

Permalink
Merge pull request #78 from Jimilian/fix_empty_topic
Browse files Browse the repository at this point in the history
Prevent receiving list of random changes for empty topic name
  • Loading branch information
rsandell authored Feb 28, 2018
2 parents d8f43ae + 47530ae commit 43564cb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.sonymobile.tools.gerrit.gerritevents.helpers.FileHelper;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Date;
Expand Down Expand Up @@ -131,10 +132,15 @@ public class Change implements GerritJsonDTO {
*/
@SuppressWarnings("unused")
private Object readResolve() {
if (topic != null) {
if (StringUtils.isNotEmpty(topic)) {
topicObject = new Topic(topic);
topic = null;
}

if (topicObject != null && StringUtils.isEmpty(topicObject.getName())) {
topicObject = null;
}

return this;
}

Expand Down Expand Up @@ -176,7 +182,10 @@ public void fromJson(JSONObject json) {
commitMessage = getString(json, COMMIT_MESSAGE);
}
if (json.containsKey(TOPIC)) {
topicObject = new Topic(getString(json, TOPIC));
String topicName = getString(json, TOPIC);
if (StringUtils.isNotEmpty(topicName)) {
topicObject = new Topic(topicName);
}
}

url = getString(json, URL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import com.sonymobile.tools.gerrit.gerritevents.dto.rest.Topic;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

/**
* A DTO representation of the topic-changed Gerrit Event.
Expand Down Expand Up @@ -61,10 +62,15 @@ public class TopicChanged extends ChangeBasedEvent {
*/
@SuppressWarnings("unused")
private Object readResolve() {
if (oldTopic != null) {
if (StringUtils.isNotEmpty(oldTopic)) {
oldTopicObject = new Topic(oldTopic);
oldTopic = null;
}

if (oldTopicObject != null && StringUtils.isEmpty(oldTopicObject.getName())) {
oldTopicObject = null;
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import com.sonymobile.tools.gerrit.gerritevents.dto.attr.PatchSet;
import com.sonymobile.tools.gerrit.gerritevents.dto.events.ChangeBasedEvent;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -71,6 +73,11 @@ public String getName() {
* @return the map of pairs change-patchset related to this topic.
*/
public Map<Change, PatchSet> getChanges(GerritQueryHandler gerritQueryHandler) {
if (StringUtils.isEmpty(name)) {
logger.error("Topic name can not be empty");
return Collections.emptyMap();
}

if (changes == null) {
Map<Change, PatchSet> temp = new HashMap<Change, PatchSet>();
try {
Expand Down

0 comments on commit 43564cb

Please sign in to comment.