From 062878f97b8d28463e040ed923d1f44763b5c848 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 4 Aug 2020 17:59:13 +0200 Subject: [PATCH] Issue #5083 - Convert synchronized usages to AutoLock. Fixes after merge. Signed-off-by: Simone Bordet --- .../jetty/server/handler/ContextHandler.java | 96 ++++++++----------- 1 file changed, 39 insertions(+), 57 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 5e993ffd6482..c3cfd42eb274 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -87,7 +87,6 @@ import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.thread.AutoLock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -185,7 +184,6 @@ public enum ContextStatus DESTROYED } - private final AutoLock _lock = new AutoLock(); protected ContextStatus _contextStatus = ContextStatus.NOTSET; protected Context _scontext; private final AttributesMap _attributes; @@ -1846,13 +1844,10 @@ public Class loadClass(String className) throws ClassNotFoundException if (className == null) return null; - try (AutoLock l = _lock.lock()) - { - if (_classLoader == null) - return Loader.loadClass(className); + if (_classLoader == null) + return Loader.loadClass(className); - return _classLoader.loadClass(className); - } + return _classLoader.loadClass(className); } public void addLocaleEncoding(String locale, String encoding) @@ -2084,7 +2079,6 @@ public void clearAliasChecks() */ public class Context extends StaticContext { - private final AutoLock _lock = new AutoLock(); protected boolean _enabled = true; // whether or not the dynamic API is enabled for callers protected boolean _extendedListenerTypes = false; @@ -2324,60 +2318,51 @@ public Enumeration getInitParameterNames() @Override public Object getAttribute(String name) { - try (AutoLock l = _lock.lock()) - { - Object o = ContextHandler.this.getAttribute(name); - if (o == null) - o = super.getAttribute(name); - return o; - } + Object o = ContextHandler.this.getAttribute(name); + if (o == null) + o = super.getAttribute(name); + return o; } @Override public Enumeration getAttributeNames() { - try (AutoLock l = _lock.lock()) + HashSet set = new HashSet<>(); + Enumeration e = super.getAttributeNames(); + while (e.hasMoreElements()) { - HashSet set = new HashSet<>(); - Enumeration e = super.getAttributeNames(); - while (e.hasMoreElements()) - { - set.add(e.nextElement()); - } - e = ContextHandler.this.getAttributeNames(); - while (e.hasMoreElements()) - { - set.add(e.nextElement()); - } - return Collections.enumeration(set); + set.add(e.nextElement()); + } + e = ContextHandler.this.getAttributeNames(); + while (e.hasMoreElements()) + { + set.add(e.nextElement()); } + return Collections.enumeration(set); } @Override public void setAttribute(String name, Object value) { - try (AutoLock l = _lock.lock()) - { - Object oldValue = super.getAttribute(name); + Object oldValue = super.getAttribute(name); - if (value == null) - super.removeAttribute(name); - else - super.setAttribute(name, value); + if (value == null) + super.removeAttribute(name); + else + super.setAttribute(name, value); - if (!_servletContextAttributeListeners.isEmpty()) - { - ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue == null ? value : oldValue); + if (!_servletContextAttributeListeners.isEmpty()) + { + ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue == null ? value : oldValue); - for (ServletContextAttributeListener listener : _servletContextAttributeListeners) - { - if (oldValue == null) - listener.attributeAdded(event); - else if (value == null) - listener.attributeRemoved(event); - else - listener.attributeReplaced(event); - } + for (ServletContextAttributeListener listener : _servletContextAttributeListeners) + { + if (oldValue == null) + listener.attributeAdded(event); + else if (value == null) + listener.attributeRemoved(event); + else + listener.attributeReplaced(event); } } } @@ -2385,17 +2370,14 @@ else if (value == null) @Override public void removeAttribute(String name) { - try (AutoLock l = _lock.lock()) + Object oldValue = super.getAttribute(name); + super.removeAttribute(name); + if (oldValue != null && !_servletContextAttributeListeners.isEmpty()) { - Object oldValue = super.getAttribute(name); - super.removeAttribute(name); - if (oldValue != null && !_servletContextAttributeListeners.isEmpty()) + ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue); + for (ServletContextAttributeListener listener : _servletContextAttributeListeners) { - ServletContextAttributeEvent event = new ServletContextAttributeEvent(_scontext, name, oldValue); - for (ServletContextAttributeListener listener : _servletContextAttributeListeners) - { - listener.attributeRemoved(event); - } + listener.attributeRemoved(event); } } }