Skip to content

Commit 7dea756

Browse files
author
Enric Sala
committed
Prevent throwing an exception when building an empty writer
1 parent 6b6ab15 commit 7dea756

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

influxdb-client/WriteBuilder.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,19 @@
4747

4848
% Build line protocol
4949
function str = build(obj)
50-
builder = java.lang.StringBuilder();
51-
for i = 1:length(obj.Items)
52-
item = obj.Items{i};
53-
builder.append(item.toLine(obj.Precision));
54-
builder.append(newline);
50+
if isempty(obj.Items)
51+
warning('this writer is empty');
52+
str = '';
53+
else
54+
builder = java.lang.StringBuilder();
55+
for i = 1:length(obj.Items)
56+
item = obj.Items{i};
57+
builder.append(item.toLine(obj.Precision));
58+
builder.append(newline);
59+
end
60+
builder.deleteCharAt(int32(builder.length() - 1));
61+
str = char(builder.toString());
5562
end
56-
builder.deleteCharAt(int32(builder.length() - 1));
57-
str = char(builder.toString());
5863
end
5964

6065
% Execute the write

0 commit comments

Comments
 (0)