From b99a5138cce39eff6c5c5374d9de90d24b03b9f2 Mon Sep 17 00:00:00 2001 From: Julian Sedding Date: Fri, 30 Sep 2016 14:08:12 +0000 Subject: [PATCH] HTTPCLIENT-1772: [OSGi] WeakList needs to support "clear" method git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1762913 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/java/org/apache/http/osgi/impl/WeakList.java | 5 +++++ .../java/org/apache/http/osgi/impl/WeakListTest.java | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/WeakList.java b/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/WeakList.java index 59ee6fd7f..5325196cc 100644 --- a/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/WeakList.java +++ b/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/WeakList.java @@ -62,6 +62,11 @@ class WeakList extends AbstractList { return innerList.add(new WeakReference(t)); } + @Override + public void clear() { + innerList.clear(); + } + private void checkReferences() { final ListIterator> references = innerList.listIterator(); while (references.hasNext()) { diff --git a/httpclient-osgi/src/test/java/org/apache/http/osgi/impl/WeakListTest.java b/httpclient-osgi/src/test/java/org/apache/http/osgi/impl/WeakListTest.java index a930fa41b..77770bf42 100644 --- a/httpclient-osgi/src/test/java/org/apache/http/osgi/impl/WeakListTest.java +++ b/httpclient-osgi/src/test/java/org/apache/http/osgi/impl/WeakListTest.java @@ -59,4 +59,15 @@ public class WeakListTest { assertTrue(thrown); } + @Test + public void clearSupported() { + final WeakList list = new WeakList(); + + list.add("hello"); + assertEquals(1, list.size()); + + list.clear(); + assertEquals(0, list.size()); + } + } \ No newline at end of file