Bug 20273 - LinkedHashMap breaks linked list when access() is called
LinkedHashMap breaks linked list when access() is called
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: libgcj
3.4.3
: P2 normal
: 4.0.1
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-02 02:56 UTC by Seth
Modified: 2005-05-30 02:08 UTC (History)
4 users (show)

See Also:
Host: i386-redhat-linux
Target: i386-redhat-linux
Build: i386-redhat-linux
Known to work:
Known to fail:
Last reconfirmed: 2005-05-27 01:00:01


Attachments
Java test case for LinkedHashMapEntry.access() bug (1.04 KB, text/plain)
2005-03-02 03:34 UTC, Seth
Details
Fix for PR 20273 (527 bytes, patch)
2005-03-02 06:37 UTC, Michael Koch
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Seth 2005-03-02 02:56:32 UTC
File: gcc/libjava/java/util/LinkedHashMap.java
CVS Version: 1.6

When using "accessOrder"-based sorting in LinkedHashMap, the linked list appears
to become broken after calling get(). I believe that this is due to a missing
line in the access() function. I believe that the following line needs to be
added after line 188:

root.pred = this;

This will relink "root.pred" to the "this" object which has been moved to the
"tail" of the linked list. Otherwise, root.pred will point to the
2nd-from-the-tail element which breaks the semantics of the linked list used in
the class. I will post some test code that exposes this problem shortly.
Comment 1 Andrew Pinski 2005-03-02 03:17:48 UTC
Do you have a testcase?
Comment 2 Seth 2005-03-02 03:34:52 UTC
Created attachment 8309 [details]
Java test case for LinkedHashMapEntry.access() bug

Simply compile and run the class with gcj. The expected output should be:

Key: 1
Key: 2
Key: 3

but the output I am getting is:

Key: 1
Key: 2
Comment 3 Andrew Pinski 2005-03-02 03:40:52 UTC
Confirmed.
Comment 4 Michael Koch 2005-03-02 06:37:19 UTC
Created attachment 8310 [details]
Fix for PR 20273

The attached patch fixes the problem. I verified with classpath/jamvm.
No mauve testcase written yet.
Comment 5 CVS Commits 2005-05-30 02:01:42 UTC
Subject: Bug 20273

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	tromey@gcc.gnu.org	2005-05-30 02:01:15

Modified files:
	libjava        : ChangeLog 
	libjava/java/util: LinkedHashMap.java 

Log message:
	2005-05-29  Michael Koch  <konqueror@gmx.de>
	
	PR libgcj/20273:
	* java/util/LinkedHashMap.java (access): Set 'root.pred'.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&r1=1.3638&r2=1.3639
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/LinkedHashMap.java.diff?cvsroot=gcc&r1=1.6&r2=1.7

Comment 6 CVS Commits 2005-05-30 02:02:17 UTC
Subject: Bug 20273

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tromey@gcc.gnu.org	2005-05-30 02:02:03

Modified files:
	libjava        : ChangeLog 
	libjava/java/util: LinkedHashMap.java 

Log message:
	2005-05-29  Michael Koch  <konqueror@gmx.de>
	
	PR libgcj/20273:
	* java/util/LinkedHashMap.java (access): Set 'root.pred'.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.3391.2.79&r2=1.3391.2.80
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/libjava/java/util/LinkedHashMap.java.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.6&r2=1.6.2.1

Comment 7 Tom Tromey 2005-05-30 02:08:08 UTC
I checked this in to 4.0, the trunk, and Classpath.
I put the test case in Mauve.
I'm not planning to put the fix into 3.4.x, but someone could if
they wanted to.