commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Janek Bogucki <...@studylink.com>
Subject Re: [collections] ReferenceMap changed for WeakIdentityMap but now broken
Date Wed, 24 Mar 2004 22:58:22 GMT
On Tue, 2004-03-23 at 23:01, Stephen Colebourne wrote:
>  I can't spot the problem, so I'm posting it in case someone else wants to
> take a look and tell me my stupid mistake ;-)

Sorry this isn't expressed as unit test but just in case this is enough
to go on I've posted it. I added a System.out.println to
testPurgeValues() just before the invocation of isEmpty()

  System.out.println("testPurgeValues: before isEmpty: " + iterations );
  testMap.isEmpty();

then two more in purge(Reference) to get this output

    [junit] testPurgeValues: before isEmpty: 1
    [junit] purge()
    [junit] purge(Reference)
    [junit] purge(Reference): entry: null
    [junit] testPurgeValues: before isEmpty: 2
    [junit] purge()
    [junit] testPurgeValues: before isEmpty: 3
    [junit] purge()
    [junit] testPurgeValues: before isEmpty: 4
    [junit] purge()
    [junit] testPurgeValues: before isEmpty: 5


So purge correctly invokes purge(Reference) but purge(Reference) gets
null for entry and never enters the while block.

	private void purge(Reference ref) {
		System.out.println("purge(Reference)");
		// The hashCode of the reference is the hashCode of the
		// mapping key, even if the reference refers to the 
		// mapping value...
		int hash = hash(ref);
		int index = hashIndex(hash, data.length);
		HashEntry previous = null;
		HashEntry entry = data[index];

		System.out.println("purge(Reference): entry: " + entry);
		while (entry != null) {
			if (((ReferenceEntry) entry).purge(ref)) {
				if (previous == null) {
					data[index] = entry.next;
				} else {
					previous.next = entry.next;
				}
				this.size--;
				return;
			}
			previous = entry;
			entry = entry.next;
		}

	}

-Janek

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message