Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public StatsTrack() {
* @param stat the byte[] stat to be initialized with
*/
public StatsTrack(byte[] stat) {
this(new String(stat, StandardCharsets.UTF_8));
this(stat == null ? null : new String(stat, StandardCharsets.UTF_8));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

package org.apache.zookeeper.test;

import org.apache.zookeeper.Quotas;
import org.apache.zookeeper.StatsTrack;
import org.apache.zookeeper.server.DataTree;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -132,4 +134,29 @@ public void testUpwardCompatibility() {
Assert.assertEquals(-1, st.getByteHardLimit());
Assert.assertEquals(-1, st.getCountHardLimit());
}

@org.junit.jupiter.api.Test
public void testCreateNodeWhenQuotaStatDataIsNull() throws Exception {
final DataTree tree = new DataTree();
final String path = "/bug";
final String childPath = path + "/child";
final String quotaPath = Quotas.quotaPath(path);
final String limitPath = Quotas.limitPath(path);
final String statPath = Quotas.statPath(path);

tree.createNode(path, new byte[0], null, -1, tree.getNode("/").stat.getCversion() + 1, 1, 1);
tree.createNode(quotaPath, null, null, -1, 1, 1, 1);

StatsTrack limit = new StatsTrack();
limit.setCountHardLimit(10);
tree.createNode(limitPath, limit.getStatsBytes(), null, -1, 1, 1, 1);

tree.createNode(statPath, new StatsTrack().getStatsBytes(), null, -1, 1, 1, 1);
tree.setData(statPath, null, -1, 2, 2);

tree.createNode(childPath, new byte[] { 1 }, null, -1, tree.getNode(path).stat.getCversion() + 1, 3, 3);

Assert.assertNotNull(tree.getNode(childPath));
Assert.assertNotNull(tree.getNode(statPath).getData());
}
}