From 236f5d57bff8004716614ec9c35b6a0e58e2c85a Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 5 Sep 2013 12:24:28 +1000 Subject: [PATCH 1/6] 414431 Avoid debug NPE race --- .../main/java/org/eclipse/jetty/http/HttpGenerator.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java index 85d70df09ab..0d95759c44b 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpGenerator.java @@ -1079,11 +1079,14 @@ public class HttpGenerator extends AbstractGenerator @Override public String toString() { + Buffer header=_header; + Buffer buffer=_buffer; + Buffer content=_content; return String.format("%s{s=%d,h=%d,b=%d,c=%d}", getClass().getSimpleName(), _state, - _header == null ? -1 : _header.length(), - _buffer == null ? -1 : _buffer.length(), - _content == null ? -1 : _content.length()); + header == null ? -1 : header.length(), + buffer == null ? -1 : buffer.length(), + content == null ? -1 : content.length()); } } From 9db0101d698e85ca2e21ffc27d698c1df02f4d33 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Tue, 10 Sep 2013 12:03:03 +0200 Subject: [PATCH 2/6] ProxyServletTest create test dir if it doesn't exist --- .../jetty/servlets/ProxyServletTest.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java index e8e761fd1f8..f0d343c2d9d 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java @@ -18,6 +18,22 @@ package org.eclipse.jetty.servlets; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.Socket; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import junit.framework.Assert; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; @@ -34,23 +50,9 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; -import org.hamcrest.core.Is; -import org.hamcrest.core.IsEqual; import org.junit.After; import org.junit.Test; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.MalformedURLException; -import java.net.Socket; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -138,7 +140,9 @@ public class ProxyServletTest public void testBigDownloadWithSlowReader() throws Exception { // Create a 6 MiB file - final File file = File.createTempFile("test_", null, MavenTestingUtils.getTargetTestingDir()); + File targetTestingDir = MavenTestingUtils.getTargetTestingDir(); + targetTestingDir.mkdir(); + final File file = File.createTempFile("test_", null, targetTestingDir); file.deleteOnExit(); FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[1024]; From 911043b5be2b1a87905401693b959f80ce38a629 Mon Sep 17 00:00:00 2001 From: Thomas Becker Date: Tue, 10 Sep 2013 12:03:03 +0200 Subject: [PATCH 3/6] ProxyServletTest create test dir if it doesn't exist --- .../jetty/servlets/ProxyServletTest.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java index e8e761fd1f8..f0d343c2d9d 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/ProxyServletTest.java @@ -18,6 +18,22 @@ package org.eclipse.jetty.servlets; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.Socket; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import junit.framework.Assert; import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.HttpClient; @@ -34,23 +50,9 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; -import org.hamcrest.core.Is; -import org.hamcrest.core.IsEqual; import org.junit.After; import org.junit.Test; -import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.*; -import java.net.MalformedURLException; -import java.net.Socket; -import java.util.Arrays; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -138,7 +140,9 @@ public class ProxyServletTest public void testBigDownloadWithSlowReader() throws Exception { // Create a 6 MiB file - final File file = File.createTempFile("test_", null, MavenTestingUtils.getTargetTestingDir()); + File targetTestingDir = MavenTestingUtils.getTargetTestingDir(); + targetTestingDir.mkdir(); + final File file = File.createTempFile("test_", null, targetTestingDir); file.deleteOnExit(); FileOutputStream fos = new FileOutputStream(file); byte[] buffer = new byte[1024]; From c842c5c50528ea3b4e86cdc72d61503e25679bd1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 12 Sep 2013 10:40:26 +1000 Subject: [PATCH 4/6] 416990 JMX names statically unique --- .../src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 0637b59b715..5475c54b04f 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -49,10 +49,10 @@ import org.eclipse.jetty.util.thread.ShutdownThread; public class MBeanContainer extends AbstractLifeCycle implements Container.Listener, Dumpable { private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); + private final static HashMap _unique = new HashMap(); private final MBeanServer _server; private final WeakHashMap _beans = new WeakHashMap(); - private final HashMap _unique = new HashMap(); private final WeakHashMap> _relations = new WeakHashMap>(); private String _domain = null; From 3eb84f99a45d81acf55deb1c12be9ac9b6042d1f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 12 Sep 2013 12:29:24 +1000 Subject: [PATCH 5/6] 416990 JMX names statically unique Fixed monitor test to reset uniqueness --- .../org/eclipse/jetty/jmx/MBeanContainer.java | 20 +++++++++++++++---- .../jetty/monitor/AttrEventTriggerTest.java | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 5475c54b04f..39536adc4df 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -49,7 +49,15 @@ import org.eclipse.jetty.util.thread.ShutdownThread; public class MBeanContainer extends AbstractLifeCycle implements Container.Listener, Dumpable { private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); - private final static HashMap _unique = new HashMap(); + private final static HashMap __unique = new HashMap(); + + public final static void resetUnique() + { + synchronized (__unique) + { + __unique.clear(); + } + } private final MBeanServer _server; private final WeakHashMap _beans = new WeakHashMap(); @@ -283,9 +291,13 @@ public class MBeanContainer extends AbstractLifeCycle implements Container.Liste } String basis = buf.toString(); - Integer count = _unique.get(basis); - count = count == null ? 0 : 1 + count; - _unique.put(basis, count); + Integer count; + synchronized (__unique) + { + count = __unique.get(basis); + count = count == null ? 0 : 1 + count; + __unique.put(basis, count); + } //if no explicit domain, create one String domain = _domain; diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java index ce87ee20841..90975192bd4 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java @@ -97,6 +97,7 @@ public class AttrEventTriggerTest MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); MBeanContainer mBeanContainer = new MBeanContainer(mBeanServer); mBeanContainer.addBean(Log.getLog()); + MBeanContainer.resetUnique(); _counter = _handler.getRequestCounter(); mBeanContainer.addBean(_counter); From 423dc1e44340937586d54b68651971650ce048b4 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 12 Sep 2013 12:52:28 +1000 Subject: [PATCH 6/6] 416990 JMX names statically unique Concurrent access to counter --- .../org/eclipse/jetty/jmx/MBeanContainer.java | 25 ++++++++++++++----- .../jetty/monitor/AttrEventTriggerTest.java | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 4e7e5ff6c70..f1f0637d600 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -23,6 +23,9 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; @@ -42,8 +45,13 @@ import org.eclipse.jetty.util.log.Logger; public class MBeanContainer implements Container.InheritedListener, Dumpable { private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); - private final static HashMap _unique = new HashMap(); + private final static ConcurrentMap __unique = new ConcurrentHashMap(); + public static void resetUnique() + { + __unique.clear(); + } + private final MBeanServer _mbeanServer; private final WeakHashMap _beans = new WeakHashMap(); private String _domain = null; @@ -186,11 +194,16 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable buf.append(",").append("name=").append(name); String basis = buf.toString(); - Integer count = _unique.get(basis); - count = count == null ? 0 : 1 + count; - _unique.put(basis, count); - - oname = ObjectName.getInstance(domain + ":" + basis + ",id=" + count); + + AtomicInteger count = __unique.get(basis); + if (count==null) + { + count=__unique.putIfAbsent(basis,new AtomicInteger()); + if (count==null) + count=__unique.get(basis); + } + + oname = ObjectName.getInstance(domain + ":" + basis + ",id=" + count.getAndIncrement()); } ObjectInstance oinstance = _mbeanServer.registerMBean(mbean, oname); diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java index 72d60606033..f1416e39fdb 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java @@ -98,6 +98,7 @@ public class AttrEventTriggerTest _handler = new TestHandler(); _server.setHandler(_handler); + MBeanContainer.resetUnique(); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); _mBeanContainer = new MBeanContainer(mBeanServer); _server.addBean(_mBeanContainer,true);