From 49f7bc37afef7ebd1e2cf74b0d893dd4089cd799 Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Thu, 14 Apr 2016 21:05:34 +0100 Subject: [PATCH] Make DockerTemplateOptions values null safe --- .../options/DockerTemplateOptions.java | 22 +++++++++---------- .../docker/internal/NullSafeCopies.java | 8 +++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java b/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java index bff0d9c428..8a42253bad 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java +++ b/apis/docker/src/main/java/org/jclouds/docker/compute/options/DockerTemplateOptions.java @@ -83,15 +83,15 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable private static final String NO_IMAGE = "jclouds-placeholder-for-image"; protected List dns = ImmutableList.of(); - protected String hostname; - protected Integer memory; - protected Integer cpuShares; - protected List entrypoint = ImmutableList.of(); - protected List commands = ImmutableList.of(); + @Nullable protected String hostname; + @Nullable protected Integer memory; + @Nullable protected Integer cpuShares; + @Nullable List entrypoint; + @Nullable List commands; protected Map volumes = ImmutableMap.of(); - protected List env = ImmutableList.of(); + @Nullable protected List env; protected Map portBindings = ImmutableMap.of(); - protected String networkMode; + @Nullable protected String networkMode; protected Map extraHosts = ImmutableMap.of(); protected List volumesFrom = ImmutableList.of(); protected boolean privileged; @@ -189,12 +189,12 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable } public DockerTemplateOptions dns(Iterable dns) { - this.dns = NullSafeCopies.copyWithNullOf(dns); + this.dns = NullSafeCopies.copyOf(dns); return this; } public DockerTemplateOptions dns(String...dns) { - this.dns = NullSafeCopies.copyWithNullOf(dns); + this.dns = NullSafeCopies.copyOf(dns); return this; } @@ -278,7 +278,7 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable * @param extraHosts the map of host names to IP addresses */ public DockerTemplateOptions extraHosts(Map extraHosts) { - this.extraHosts = NullSafeCopies.copyWithNullOf(extraHosts); + this.extraHosts = NullSafeCopies.copyOf(extraHosts); return this; } @@ -288,7 +288,7 @@ public class DockerTemplateOptions extends TemplateOptions implements Cloneable * @param volumesFrom the list of container names */ public DockerTemplateOptions volumesFrom(Iterable volumesFrom) { - this.volumesFrom = NullSafeCopies.copyWithNullOf(volumesFrom); + this.volumesFrom = NullSafeCopies.copyOf(volumesFrom); return this; } diff --git a/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java b/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java index b6e190ce24..f3d9eb860c 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java +++ b/apis/docker/src/main/java/org/jclouds/docker/internal/NullSafeCopies.java @@ -34,6 +34,14 @@ public class NullSafeCopies { return list != null ? ImmutableList.copyOf(list) : ImmutableList. of(); } + public static List copyOf(@Nullable Iterable list) { + return list != null ? ImmutableList.copyOf(list) : ImmutableList. of(); + } + + public static List copyOf(@Nullable E[] array) { + return array != null ? ImmutableList.copyOf(array) : ImmutableList. of(); + } + /** * Copies given List with keeping null value if provided. *