Hi Robert,
Had a little time to look at the WeakHashtable. Much cleaner w/o reflection!
A couple things occurred to me as I looked.
1) The instances of Referenced are not cleared from the underlying table if their underlying references are cleared.
2) Passing null keys/values to put() does not result in a NPE.
I attached a patch to the WeakHashtableTest that tests for these.
One thought on #1 is to make Referenced a subclass of WeakReference instead of a wrapper. You can then keep a ReferenceQueue and poll it to remove cleared references from the hashtable whenever get() is called. This is similar to what WeakHashMap does.
Best,
Brian Stansberry
Do you Yahoo!?
Check out the new Yahoo! Front Page. www.yahoo.com
Index: WeakHashtableTest.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/logging/optional/src/test/org/apache/commons/logging/impl/WeakHashtableTest.java,v retrieving revision 1.1 diff -u -r1.1 WeakHashtableTest.java --- WeakHashtableTest.java 10 Nov 2004 22:59:54 -0000 1.1 +++ WeakHashtableTest.java 11 Nov 2004 07:04:14 -0000 @@ -153,6 +153,24 @@ weakHashtable.put(anotherKey, new Long(1066)); assertEquals(new Long(1066), weakHashtable.get(anotherKey)); + + // Test compliance with the hashtable API re nulls + Exception caught = null; + try { + weakHashtable.put(null, new Object()); + } + catch (Exception e) { + caught = e; + } + assertNotNull("did not throw an exception adding a null key", caught); + caught = null; + try { + weakHashtable.put(new Object(), null); + } + catch (Exception e) { + caught = e; + } + assertNotNull("did not throw an exception adding a null value", caught); } /** Tests public void putAll(MapÊt) */ @@ -214,5 +232,8 @@ bytz = bytz * 2; } } + + // Test that the released objects are not taking space in the table + assertEquals("underlying table not emptied", 0, weakHashtable.size()); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]