Skip to content

Commit bca456d

Browse files
authored
Make sure items aren't null in BuildConfiguration.Builder collections (GoogleContainerTools#470)
1 parent 072ee24 commit bca456d

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

‎jib-core/src/main/java/com/google/cloud/tools/jib/builder/BuildConfiguration.java‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import com.google.cloud.tools.jib.image.json.BuildableManifestTemplate;
2222
import com.google.cloud.tools.jib.image.json.V22ManifestTemplate;
2323
import com.google.cloud.tools.jib.registry.credentials.RegistryCredentials;
24+
import com.google.common.base.Preconditions;
2425
import com.google.common.base.Splitter;
2526
import com.google.common.collect.ImmutableList;
2627
import com.google.common.collect.ImmutableMap;
2728
import java.util.ArrayList;
28-
import java.util.HashMap;
2929
import java.util.List;
3030
import java.util.Map;
3131
import javax.annotation.Nullable;
@@ -44,10 +44,10 @@ public static class Builder {
4444
@Nullable private String targetImageCredentialHelperName;
4545
@Nullable private RegistryCredentials knownTargetRegistryCredentials;
4646
@Nullable private String mainClass;
47-
private List<String> javaArguments = new ArrayList<>();
48-
private List<String> jvmFlags = new ArrayList<>();
49-
private Map<String, String> environmentMap = new HashMap<>();
50-
private List<String> exposedPorts = new ArrayList<>();
47+
private ImmutableList<String> javaArguments = ImmutableList.of();
48+
private ImmutableList<String> jvmFlags = ImmutableList.of();
49+
private ImmutableMap<String, String> environmentMap = ImmutableMap.of();
50+
private ImmutableList<String> exposedPorts = ImmutableList.of();
5151
private Class<? extends BuildableManifestTemplate> targetFormat = V22ManifestTemplate.class;
5252
@Nullable private CacheConfiguration applicationLayersCacheConfiguration;
5353
@Nullable private CacheConfiguration baseImageLayersCacheConfiguration;
@@ -98,28 +98,33 @@ public Builder setMainClass(@Nullable String mainClass) {
9898

9999
public Builder setJavaArguments(@Nullable List<String> javaArguments) {
100100
if (javaArguments != null) {
101-
this.javaArguments = javaArguments;
101+
Preconditions.checkArgument(!javaArguments.contains(null));
102+
this.javaArguments = ImmutableList.copyOf(javaArguments);
102103
}
103104
return this;
104105
}
105106

106107
public Builder setJvmFlags(@Nullable List<String> jvmFlags) {
107108
if (jvmFlags != null) {
108-
this.jvmFlags = jvmFlags;
109+
Preconditions.checkArgument(!jvmFlags.contains(null));
110+
this.jvmFlags = ImmutableList.copyOf(jvmFlags);
109111
}
110112
return this;
111113
}
112114

113115
public Builder setEnvironment(@Nullable Map<String, String> environmentMap) {
114116
if (environmentMap != null) {
115-
this.environmentMap = environmentMap;
117+
Preconditions.checkArgument(
118+
!environmentMap.containsKey(null) && !environmentMap.containsValue(null));
119+
this.environmentMap = ImmutableMap.copyOf(environmentMap);
116120
}
117121
return this;
118122
}
119123

120124
public Builder setExposedPorts(@Nullable List<String> exposedPorts) {
121125
if (exposedPorts != null) {
122-
this.exposedPorts = exposedPorts;
126+
Preconditions.checkArgument(!exposedPorts.contains(null));
127+
this.exposedPorts = ImmutableList.copyOf(exposedPorts);
123128
}
124129
return this;
125130
}
@@ -198,10 +203,10 @@ public BuildConfiguration build() {
198203
targetImageCredentialHelperName,
199204
knownTargetRegistryCredentials,
200205
mainClass,
201-
ImmutableList.copyOf(javaArguments),
202-
ImmutableList.copyOf(jvmFlags),
203-
ImmutableMap.copyOf(environmentMap),
204-
ImmutableList.copyOf(exposedPorts),
206+
javaArguments,
207+
jvmFlags,
208+
environmentMap,
209+
exposedPorts,
205210
targetFormat,
206211
applicationLayersCacheConfiguration,
207212
baseImageLayersCacheConfiguration,

0 commit comments

Comments
 (0)