influxdata / influxdb-java

Java client for InfluxDB
MIT License
1.18k stars 477 forks source link

`BatchPoints.Builder` not reusable #952

Open jpalus opened 1 year ago

jpalus commented 1 year ago

There's nothing in BatchPoints.Builder javadoc that would warn against calling build() multiple times: https://github.com/influxdata/influxdb-java/blob/b1d1d8a2ed4430f6b6ac271362acab7b493be984/src/main/java/org/influxdb/dto/BatchPoints.java#L54-L57 https://github.com/influxdata/influxdb-java/blob/b1d1d8a2ed4430f6b6ac271362acab7b493be984/src/main/java/org/influxdb/dto/BatchPoints.java#L151-L156

and nothing in build() method itself that would cause ie exception: https://github.com/influxdata/influxdb-java/blob/b1d1d8a2ed4430f6b6ac271362acab7b493be984/src/main/java/org/influxdb/dto/BatchPoints.java#L156-L174

but creating multiple BatchPoints instances from BatchPoints.Builder is not actually safe since BatchPoints.Builder does not make defensive copy of this.points: https://github.com/influxdata/influxdb-java/blob/b1d1d8a2ed4430f6b6ac271362acab7b493be984/src/main/java/org/influxdb/dto/BatchPoints.java#L162

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.