Bug 32862 - bug in EnumMap implementation
Summary: bug in EnumMap implementation
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: java (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-23 08:02 UTC by Debian GCC Maintainers
Modified: 2007-08-07 17:38 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-23 16:11:28


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Debian GCC Maintainers 2007-07-23 08:02:24 UTC
[forwarded from http://bugs.debian.org/423160]

seen with trunk 20070720

The gij implementation of EnumMap class contains a flaw: it returns
strange java.lang.Object classes for missing elements. The error can be
demonstrated with this program:

=== Cut ===
import java.util.*;

public class Test {
	enum TestEnum {
		FIRST, SECOND
	}

	public static void main(String[] args) {
		Map<TestEnum, String> map = new EnumMap<TestEnum, String>(TestEnum.class);
		map.put(TestEnum.FIRST, "first");
		System.out.println(map);
		System.out.println(map.containsKey(TestEnum.SECOND));
		System.out.println(map.get(TestEnum.SECOND));
	}
}

$ gcj -C Test.java

tmp $ gij Test
{FIRST=first}
false
Exception in thread "main" java.lang.ClassCastException:
java.lang.Object cannot be cast to java.lang.String
   at Test.main(Test.java:13)

tmp $ java Test
{FIRST=first}
false
null

=== Cut ===

As you can see, Sun Java (the last call) returns correct null, while
GNU libgcj returns bogus java.lang.Object.
Comment 1 Tom Tromey 2007-07-23 16:11:28 UTC
I have a fix I'm testing.
Comment 2 cvs-commit@developer.classpath.org 2007-07-24 15:27:11 UTC
Subject: Bug 32862

CVSROOT:	/cvsroot/classpath
Module name:	classpath
Changes by:	Tom Tromey <tromey>	07/07/24 15:26:36

Modified files:
	.              : ChangeLog 
	java/util      : EnumMap.java 

Log message:
		PR java/32862:
		* java/util/EnumMap.java (get): Special case emptySlot.
		(clone): Rewrote.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.9354&r2=1.9355
http://cvs.savannah.gnu.org/viewcvs/classpath/java/util/EnumMap.java?cvsroot=classpath&r1=1.4&r2=1.5



Comment 3 Tom Tromey 2007-08-07 17:38:43 UTC
Fixed via classpath import.