[Bug java/32862] New: bug in EnumMap implementation

debian-gcc at lists dot debian dot org gcc-bugzilla@gcc.gnu.org
Mon Jul 23 08:02:00 GMT 2007


[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.


-- 
           Summary: bug in EnumMap implementation
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: debian-gcc at lists dot debian dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32862



More information about the Java-prs mailing list