Skip to content

Commit

Permalink
Modifies ColumnVisibility.flatten() to have no side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
keith-turner committed Oct 21, 2024
1 parent 68cb5aa commit 6ed1945
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,22 @@ public static Node normalize(Node root, byte[] expression) {
public static Node normalize(Node root, byte[] expression, NodeComparator comparator) {
if (root.type != NodeType.TERM) {
TreeSet<Node> rolledUp = new TreeSet<>(comparator);
java.util.Iterator<Node> itr = root.children.iterator();
while (itr.hasNext()) {
Node c = normalize(itr.next(), expression, comparator);
if (c.type == root.type) {
rolledUp.addAll(c.children);
itr.remove();
for(Node c : root.children){
Node nc = normalize(c, expression, comparator);
if (nc.type == root.type) {
rolledUp.addAll(nc.children);
}else{
rolledUp.add(nc);
}
}
rolledUp.addAll(root.children);
root.children.clear();
root.children.addAll(rolledUp);

// need to promote a child if it's an only child
if (root.children.size() == 1) {
return root.children.get(0);
if(rolledUp.size() == 1){
return rolledUp.first();
}

Node newRoot = new Node(root.type, root.start);
newRoot.children=List.copyOf(rolledUp);
return newRoot;
}

return root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.charset.StandardCharsets;
import java.util.Comparator;

import org.apache.accumulo.core.security.ColumnVisibility.Node;
Expand Down Expand Up @@ -90,7 +91,8 @@ public void testBadCharacters() {
public void normalized(String... values) {
for (int i = 0; i < values.length; i += 2) {
ColumnVisibility cv = new ColumnVisibility(values[i].getBytes(UTF_8));
assertArrayEquals(cv.flatten(), values[i + 1].getBytes(UTF_8));
byte[] flattened = cv.flatten();
assertArrayEquals(flattened, values[i + 1].getBytes(UTF_8), new String(flattened, UTF_8)+" != "+values[i+1]);
}
}

Expand Down

0 comments on commit 6ed1945

Please sign in to comment.