Skip to content

Commit

Permalink
Avoid NPE at using MutableProjectConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
  • Loading branch information
RomanNikitenko committed Aug 3, 2017
1 parent 2611194 commit 5661a37
Showing 1 changed file with 16 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;

import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;

Expand Down Expand Up @@ -55,7 +56,7 @@ public MutableProjectConfig() {

@Override
public String getName() {
return name;
return firstNonNull(name, "");
}

public void setName(String name) {
Expand All @@ -64,7 +65,7 @@ public void setName(String name) {

@Override
public String getPath() {
return path;
return firstNonNull(path, "");
}

public void setPath(String path) {
Expand All @@ -73,7 +74,7 @@ public void setPath(String path) {

@Override
public String getDescription() {
return description;
return firstNonNull(description, "");
}

public void setDescription(String description) {
Expand All @@ -82,7 +83,7 @@ public void setDescription(String description) {

@Override
public String getType() {
return type;
return firstNonNull(type, "");
}

public void setType(String type) {
Expand All @@ -91,11 +92,7 @@ public void setType(String type) {

@Override
public List<String> getMixins() {
if (mixins == null) {
mixins = newArrayList();
}

return mixins;
return firstNonNull(mixins, newArrayList());
}

public void setMixins(List<String> mixins) {
Expand All @@ -104,11 +101,7 @@ public void setMixins(List<String> mixins) {

@Override
public Map<String, List<String>> getAttributes() {
if (attributes == null) {
attributes = newHashMap();
}

return attributes;
return firstNonNull(attributes, newHashMap());
}

public void setAttributes(Map<String, List<String>> attributes) {
Expand All @@ -117,35 +110,25 @@ public void setAttributes(Map<String, List<String>> attributes) {

@Override
public MutableSourceStorage getSource() {
if (sourceStorage == null) {
sourceStorage = new MutableSourceStorage();
}

return sourceStorage;
return firstNonNull(sourceStorage, new MutableSourceStorage());
}

public void setSource(SourceStorage sourceStorage) {
this.sourceStorage = new MutableSourceStorage(sourceStorage);
}

public Map<String, String> getOptions() {
if (options == null) {
options = newHashMap();
}
return options;
return firstNonNull(options, newHashMap());
}

public void setOptions(Map<String, String> options) {
this.options = options;
}

public List<CommandDto> getCommands() {
if (commands == null) {
commands = newArrayList();
}
return commands;
return firstNonNull(commands, newArrayList());
}

public void setCommands(List<CommandDto> commands) {
this.commands = commands;
}
Expand All @@ -156,10 +139,7 @@ public void setCommands(List<CommandDto> commands) {
* @return the list of {@link NewProjectConfig} to creating projects
*/
public List<NewProjectConfig> getProjects() {
if (projects == null) {
return newArrayList();
}
return projects;
return firstNonNull(projects, newArrayList());
}

/**
Expand Down Expand Up @@ -188,7 +168,7 @@ public MutableSourceStorage() {

@Override
public String getType() {
return type;
return firstNonNull(type, "");
}

public void setType(String type) {
Expand All @@ -197,7 +177,7 @@ public void setType(String type) {

@Override
public String getLocation() {
return location;
return firstNonNull(location, "");
}

public void setLocation(String location) {
Expand All @@ -206,11 +186,7 @@ public void setLocation(String location) {

@Override
public Map<String, String> getParameters() {
if (parameters == null) {
parameters = newHashMap();
}

return parameters;
return firstNonNull(parameters, newHashMap());
}

public void setParameters(Map<String, String> parameters) {
Expand Down

0 comments on commit 5661a37

Please sign in to comment.