-
Notifications
You must be signed in to change notification settings - Fork 477
Description
There's nothing in BatchPoints.Builder
javadoc that would warn against calling build()
multiple times:
influxdb-java/src/main/java/org/influxdb/dto/BatchPoints.java
Lines 54 to 57 in b1d1d8a
/** | |
* The Builder to create a new BatchPoints instance. | |
*/ | |
public static final class Builder { |
influxdb-java/src/main/java/org/influxdb/dto/BatchPoints.java
Lines 151 to 156 in b1d1d8a
/** | |
* Create a new BatchPoints instance. | |
* | |
* @return the created BatchPoints. | |
*/ | |
public BatchPoints build() { |
and nothing in build()
method itself that would cause ie exception:
influxdb-java/src/main/java/org/influxdb/dto/BatchPoints.java
Lines 156 to 174 in b1d1d8a
public BatchPoints build() { | |
BatchPoints batchPoints = new BatchPoints(); | |
batchPoints.setDatabase(this.database); | |
for (Point point : this.points) { | |
point.getTags().putAll(this.tags); | |
} | |
batchPoints.setPoints(this.points); | |
batchPoints.setRetentionPolicy(this.retentionPolicy); | |
batchPoints.setTags(this.tags); | |
if (null == this.consistency) { | |
this.consistency = ConsistencyLevel.ONE; | |
} | |
batchPoints.setConsistency(this.consistency); | |
if (null == this.precision) { | |
this.precision = TimeUnit.NANOSECONDS; | |
} | |
batchPoints.setPrecision(this.precision); | |
return batchPoints; | |
} |
but creating multiple BatchPoints
instances from BatchPoints.Builder
is not actually safe since BatchPoints.Builder
does not make defensive copy of this.points
:
batchPoints.setPoints(this.points); |
so ie this code will fail:
BatchPoints bp1 = builder.build();
int size = bp1.getPoints().size();
bp1.point(point);
BatchPoints bp2 = builder.build();
assertEquals(size, bp2.getPoints().size());
since bp1.point(point)
modified collection builder
refers to.