Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BatchPoints.Builder not reusable #952

Open
jpalus opened this issue Sep 1, 2023 · 0 comments
Open

BatchPoints.Builder not reusable #952

jpalus opened this issue Sep 1, 2023 · 0 comments

Comments

@jpalus
Copy link

jpalus commented Sep 1, 2023

There's nothing in BatchPoints.Builder javadoc that would warn against calling build() multiple times:

/**
* The Builder to create a new BatchPoints instance.
*/
public static final class Builder {

/**
* Create a new BatchPoints instance.
*
* @return the created BatchPoints.
*/
public BatchPoints build() {

and nothing in build() method itself that would cause ie exception:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant