influxdata / influxdata/influxdb-java

`BatchPoints.Builder` not reusable

Open
#952 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.2k
Forks
469
PR merge metrics
No merged PRs in 30d

Description

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:
```java
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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/main/java/org/influxdb/dto/BatchPoints.java, especially BatchPoints.Builder.build() and the points collection referenced around lines 156-174. Reproduce the issue with the two-build example from the report; done means separately built BatchPoints instances no longer share mutable point state.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.