Skip to content

Commit 11dc41f

Browse files
committed
Merge pull request influxdata#136 from andrewdodd/Issue-110
Fix for influxdata#110
2 parents 5f24ac8 + 878358e commit 11dc41f

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/main/java/org/influxdb/dto/Point.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public Builder useInteger(final boolean enable) {
8989
* @return the Builder instance.
9090
*/
9191
public Builder tag(final String tagName, final String value) {
92-
this.tags.put(tagName, value);
92+
Preconditions.checkArgument(tagName != null);
93+
Preconditions.checkArgument(value != null);
94+
tags.put(tagName, value);
9395
return this;
9496
}
9597

@@ -101,7 +103,9 @@ public Builder tag(final String tagName, final String value) {
101103
* @return the Builder instance.
102104
*/
103105
public Builder tag(final Map<String, String> tagsToAdd) {
104-
this.tags.putAll(tagsToAdd);
106+
for (Entry<String, String> tag : tagsToAdd.entrySet()) {
107+
tag(tag.getKey(), tag.getValue());
108+
}
105109
return this;
106110
}
107111

src/test/java/org/influxdb/dto/PointTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
import java.math.BigDecimal;
66
import java.math.BigInteger;
7+
import java.util.Map;
78
import java.util.concurrent.TimeUnit;
89
import java.util.concurrent.atomic.AtomicInteger;
910
import java.util.concurrent.atomic.AtomicLong;
1011

1112
import org.testng.annotations.Test;
1213

14+
import com.google.common.collect.Maps;
15+
1316
/**
1417
* Test for the Point DTO.
1518
*
@@ -173,4 +176,33 @@ public void testIgnoreNullPointerValue() {
173176

174177
assertThat(point.lineProtocol()).asString().isEqualTo("nulltest,foo=bar field1=\"value1\",field3=1.0 1");
175178
}
179+
180+
/**
181+
* Tests for issue #110
182+
*/
183+
@Test(expectedExceptions = IllegalArgumentException.class)
184+
public void testAddingTagsWithNullNameThrowsAnError() {
185+
Point.measurement("dontcare").tag(null, "DontCare");
186+
}
187+
188+
@Test(expectedExceptions = IllegalArgumentException.class)
189+
public void testAddingTagsWithNullValueThrowsAnError() {
190+
Point.measurement("dontcare").tag("DontCare", null);
191+
}
192+
193+
@Test(expectedExceptions = IllegalArgumentException.class)
194+
public void testAddingMapOfTagsWithNullNameThrowsAnError() {
195+
Map<String, String> map = Maps.newHashMap();
196+
map.put(null, "DontCare");
197+
Point.measurement("dontcare").tag(map);
198+
}
199+
200+
@Test(expectedExceptions = IllegalArgumentException.class)
201+
public void testAddingMapOfTagsWithNullValueThrowsAnError() {
202+
Map<String, String> map = Maps.newHashMap();
203+
map.put("DontCare", null);
204+
Point.measurement("dontcare").tag(map);
205+
}
206+
207+
176208
}

0 commit comments

Comments
 (0)