Description
ClusterConfig.Builder methods accept parameters without validation, allowing null/empty values that cause failures later or create invalid configurations.
Location
jplatform-api/src/main/java/org/flossware/jplatform/api/ClusterConfig.java
- Line 123-126: clusterName()
- Line 134-137: bindAddress()
- Line 161-166: addSeedNode()
- Line 175-178: seedNodes()
Current Code
public Builder clusterName(String clusterName) {
this.clusterName = clusterName; // No validation!
return this;
}
public Builder bindAddress(String bindAddress) {
this.bindAddress = bindAddress; // No validation!
return this;
}
public Builder addSeedNode(String seedNode) {
if (this.seedNodes == null) {
this.seedNodes = new ArrayList<>();
}
this.seedNodes.add(seedNode); // No null check!
return this;
}
public Builder seedNodes(List<String> seedNodes) {
this.seedNodes = new ArrayList<>(seedNodes); // NPE if null!
return this;
}
Problem
// Null cluster name accepted
ClusterConfig config = ClusterConfig.builder()
.clusterName(null) // Accepted!
.build();
config.getClusterName(); // Returns null
// Empty bind address accepted
ClusterConfig config = ClusterConfig.builder()
.bindAddress("") // Accepted!
.build();
// Null seed node accepted
ClusterConfig config = ClusterConfig.builder()
.addSeedNode(null) // Accepted!
.build();
config.getSeedNodes(); // Contains null!
// Null seed nodes list causes NPE
ClusterConfig config = ClusterConfig.builder()
.seedNodes(null) // NPE!
.build();
Impact
- Invalid cluster configurations accepted
- Null values cause NPE in cluster managers
- Hard to debug - errors occur far from where invalid data was set
- Violates fail-fast principle
Fix
public Builder clusterName(String clusterName) {
if (clusterName == null || clusterName.trim().isEmpty()) {
throw new IllegalArgumentException("clusterName cannot be null or empty");
}
this.clusterName = clusterName;
return this;
}
public Builder bindAddress(String bindAddress) {
if (bindAddress == null || bindAddress.trim().isEmpty()) {
throw new IllegalArgumentException("bindAddress cannot be null or empty");
}
this.bindAddress = bindAddress;
return this;
}
public Builder addSeedNode(String seedNode) {
if (seedNode == null || seedNode.trim().isEmpty()) {
throw new IllegalArgumentException("seedNode cannot be null or empty");
}
if (this.seedNodes == null) {
this.seedNodes = new ArrayList<>();
}
this.seedNodes.add(seedNode);
return this;
}
public Builder seedNodes(List<String> seedNodes) {
if (seedNodes == null) {
throw new IllegalArgumentException("seedNodes cannot be null");
}
// Validate list elements
for (String node : seedNodes) {
if (node == null || node.trim().isEmpty()) {
throw new IllegalArgumentException("seedNodes cannot contain null or empty elements");
}
}
this.seedNodes = new ArrayList<>(seedNodes);
return this;
}
Description
ClusterConfig.Builder methods accept parameters without validation, allowing null/empty values that cause failures later or create invalid configurations.
Location
jplatform-api/src/main/java/org/flossware/jplatform/api/ClusterConfig.javaCurrent Code
Problem
Impact
Fix