From 663ef83003039431e876d1f5071f73e9cab0dc94 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 27 Apr 2020 08:38:55 -0500 Subject: [PATCH] Issue #4814 - Attributes.getAttributeNames() is now defaulted The Attributes.getAttributeNames() will use the .getAttributeNameSet() by default now. Updated all Attributes.Wrapper impls to use this new behavior Signed-off-by: Joakim Erdfelt --- .../org/eclipse/jetty/server/Dispatcher.java | 19 +++++++------------ .../jetty/server/SecureRequestCustomizer.java | 6 ++---- .../org/eclipse/jetty/util/Attributes.java | 12 +++++------- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java index 40c0cae15a05..1f3aa6150c5e 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java @@ -19,9 +19,8 @@ package org.eclipse.jetty.server; import java.io.IOException; -import java.util.Collections; -import java.util.Enumeration; import java.util.HashSet; +import java.util.Set; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; @@ -294,13 +293,11 @@ public Object getAttribute(String key) } @Override - public Enumeration getAttributeNames() + public Set getAttributeNameSet() { HashSet set = new HashSet<>(); - Enumeration e = _attributes.getAttributeNames(); - while (e.hasMoreElements()) + for (String name : _attributes.getAttributeNameSet()) { - String name = e.nextElement(); if (!name.startsWith(__INCLUDE_PREFIX) && !name.startsWith(__FORWARD_PREFIX)) set.add(name); @@ -321,7 +318,7 @@ public Enumeration getAttributeNames() set.remove(FORWARD_QUERY_STRING); } - return Collections.enumeration(set); + return set; } @Override @@ -419,13 +416,11 @@ else if (key.startsWith(__INCLUDE_PREFIX)) } @Override - public Enumeration getAttributeNames() + public Set getAttributeNameSet() { HashSet set = new HashSet<>(); - Enumeration e = _attributes.getAttributeNames(); - while (e.hasMoreElements()) + for (String name : _attributes.getAttributeNameSet()) { - String name = e.nextElement(); if (!name.startsWith(__INCLUDE_PREFIX)) set.add(name); } @@ -445,7 +440,7 @@ public Enumeration getAttributeNames() set.remove(INCLUDE_QUERY_STRING); } - return Collections.enumeration(set); + return set; } @Override diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java index 8ab0c107016f..b980e3c901d9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SecureRequestCustomizer.java @@ -19,8 +19,6 @@ package org.eclipse.jetty.server; import java.security.cert.X509Certificate; -import java.util.Collections; -import java.util.Enumeration; import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -363,7 +361,7 @@ public Object getAttribute(String name) } @Override - public Enumeration getAttributeNames() + public Set getAttributeNameSet() { Set names = new HashSet<>(_attributes.getAttributeNameSet()); names.add(JAVAX_SERVLET_REQUEST_X_509_CERTIFICATE); @@ -373,7 +371,7 @@ public Enumeration getAttributeNames() String sessionAttribute = getSslSessionAttribute(); if (!StringUtil.isEmpty(sessionAttribute)) names.add(sessionAttribute); - return Collections.enumeration(names); + return names; } } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java index c4e3294da753..e276e27dfc53 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.util; +import java.util.Collections; import java.util.Enumeration; import java.util.Set; @@ -35,7 +36,10 @@ public interface Attributes Set getAttributeNameSet(); - Enumeration getAttributeNames(); + default Enumeration getAttributeNames() + { + return Collections.enumeration(getAttributeNameSet()); + } void clearAttributes(); @@ -80,12 +84,6 @@ public Object getAttribute(String name) return _attributes.getAttribute(name); } - @Override - public Enumeration getAttributeNames() - { - return _attributes.getAttributeNames(); - } - @Override public Set getAttributeNameSet() {