diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java index 6027cc8eedc..b97f986abf4 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/TreeTrie.java @@ -276,7 +276,31 @@ class TreeTrie extends AbstractTrie @Override public boolean isEmpty() { - return keySet().isEmpty(); + return isEmpty(_root); + } + + private boolean isEmpty(Node t) + { + if (t != null) + { + if (t._key != null) + return false; + + for (int i = 0; i < INDEX; i++) + { + if (t._nextIndex[i] != null) + { + if (!isEmpty(t._nextIndex[i])) + return false; + } + } + for (int i = t._nextOther.size(); i-- > 0; ) + { + if (!isEmpty(t._nextOther.get(i))) + return false; + } + } + return true; } @Override diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/TrieTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/TrieTest.java index 28a7aa3b917..aa8c51f84d1 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/TrieTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/TrieTest.java @@ -398,6 +398,20 @@ public class TrieTest assertThat(requiredCapacity(Set.of(x, y, z), true), is(1 + 3 * (Character.MAX_VALUE / 2))); } + @ParameterizedTest + @MethodSource("emptyImplementations") + public void testIsEmpty(AbstractTrie trie) throws Exception + { + assertTrue(trie.isEmpty()); + } + + @ParameterizedTest + @MethodSource("implementations") + public void testIsNotEmpty(AbstractTrie trie) throws Exception + { + assertFalse(trie.isEmpty()); + } + @ParameterizedTest @MethodSource("implementations") public void testEmptyKey(AbstractTrie trie) throws Exception