diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index aa494c761ec1..0673d9160167 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -486,13 +486,9 @@ static int getServerPort(Request request) return authority.getPort(); // Is there a scheme with a default port? - String rawScheme = uri.getScheme(); - if (StringUtil.isNotBlank(rawScheme)) - { - HttpScheme scheme = HttpScheme.CACHE.get(rawScheme); - if (scheme != null && scheme.getDefaultPort() > 0) - return scheme.getDefaultPort(); - } + HttpScheme scheme = HttpScheme.CACHE.get(request.getHttpURI().getScheme()); + if (scheme != null && scheme.getDefaultPort() > 0) + return scheme.getDefaultPort(); // Is there a local port? SocketAddress local = request.getConnectionMetaData().getLocalSocketAddress(); diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java index 812372ae754d..d26d3653d666 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/AbstractTrie.java @@ -63,7 +63,7 @@ public V remove(String s) public V get(String s) { - return get(s, 0, s.length()); + return get(s, 0, s == null ? 0 : s.length()); } public V get(ByteBuffer b) @@ -73,7 +73,7 @@ public V get(ByteBuffer b) public V getBest(String s) { - return getBest(s, 0, s.length()); + return getBest(s, 0, s == null ? 0 : s.length()); } public V getBest(byte[] b, int offset, int len) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java index aec1e8e12512..b9410d1d35fe 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/ArrayTernaryTrie.java @@ -259,12 +259,6 @@ public V get(ByteBuffer b, int offset, int len) return _value[t]; } - @Override - public V getBest(String s) - { - return getBest(0, s, 0, s.length()); - } - @Override public V getBest(String s, int offset, int length) { diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Index.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Index.java index dd52406f7d22..1202f65d95f6 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Index.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Index.java @@ -29,7 +29,7 @@ public interface Index /** * Get an exact match from a String key * - * @param s The key + * @param s The key, possibly null * @return the value for the string key */ V get(String s); @@ -45,7 +45,7 @@ public interface Index /** * Get an exact match from a String key * - * @param s The key + * @param s The key, possibly null * @param offset The offset within the string of the key * @param len the length of the key * @return the value for the string / offset / length @@ -65,7 +65,7 @@ public interface Index /** * Check if there is an exact match from a String key * - * @param s The key + * @param s The key, possibly null * @return true if there is a match, false otherwise */ default boolean contains(String s) @@ -76,7 +76,7 @@ default boolean contains(String s) /** * Get the best match from key in a String. * - * @param s The string + * @param s The string, possibly null * @param offset The offset within the string of the key * @param len the length of the key * @return The value or null if not found @@ -87,7 +87,7 @@ default boolean contains(String s) * Get the best match from key in a String, which may be * a prefix match or an exact match. * - * @param s The string + * @param s The string, possibly null * @return The value or null if not found */ V getBest(String s); 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 d5eb875df67d..cb55a282181a 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 @@ -414,6 +414,17 @@ public void testIsEmpty(AbstractTrie trie) throws Exception assertTrue(trie.isEmpty()); } + @ParameterizedTest + @MethodSource("emptyImplementations") + public void testGetNullStringKey(AbstractTrie trie) throws Exception + { + assertNull(trie.get((String)null)); + assertNull(trie.get((String)null, 0, 0)); + assertFalse(trie.contains(null)); + assertNull(trie.getBest((String)null)); + assertNull(trie.getBest((String)null, 0, 0)); + } + @ParameterizedTest @MethodSource("implementations") public void testIsNotEmpty(AbstractTrie trie) throws Exception