[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in the typed collections



Hello,

I found a bug in the typed collections (List, *Map). If one calls a
constructor of type TypedLinkedList(Collection c) NullPointerException is
thrown. Patch attached (against current CVS). 

Thanks,
Gergely

Index: TypedHashMap.java
===================================================================
RCS file: /cvsroot/sablecc/sablecc/src/org/sablecc/sablecc/TypedHashMap.java,v
retrieving revision 1.2
diff -u -r1.2 TypedHashMap.java
--- TypedHashMap.java	20 Mar 2003 03:50:57 -0000	1.2
+++ TypedHashMap.java	26 Mar 2003 09:16:51 -0000
@@ -25,10 +25,18 @@
 
   public TypedHashMap(Map map)
   {
-    super(map);
+    super();
 
     keyCast = NoCast.instance;
     valueCast = NoCast.instance;
+    
+    Iterator entryIter = map.entrySet().iterator();
+    while (entryIter.hasNext()) {
+	Map.Entry entry = (Map.Entry) entryIter.next();
+	this.put(entry.getKey(),entry.getValue());
+    }
+
+    
   }
 
   public TypedHashMap(Cast keyCast, Cast valueCast)
@@ -46,10 +54,17 @@
 
   public TypedHashMap(Map map, Cast keyCast, Cast valueCast)
   {
-    super(map);
+    super();
 
     this.keyCast = keyCast;
     this.valueCast = valueCast;
+    
+    Iterator entryIter = map.entrySet().iterator();
+    while (entryIter.hasNext()) {
+	Map.Entry entry = (Map.Entry) entryIter.next();
+	this.put(entry.getKey(),entry.getValue());
+    }
+
   }
 
   public Cast getKeyCast()
Index: TypedTreeMap.java
===================================================================
RCS file: /cvsroot/sablecc/sablecc/src/org/sablecc/sablecc/TypedTreeMap.java,v
retrieving revision 1.2
diff -u -r1.2 TypedTreeMap.java
--- TypedTreeMap.java	19 Mar 2003 04:37:52 -0000	1.2
+++ TypedTreeMap.java	26 Mar 2003 09:16:51 -0000
@@ -70,18 +70,32 @@
 
   public TypedTreeMap(Map map, Cast keyCast, Cast valueCast)
   {
-    super(map);
+    super();
 
     this.keyCast = keyCast;
     this.valueCast = valueCast;
+
+    Iterator entryIter = map.entrySet().iterator();
+    while (entryIter.hasNext()) {
+    	Map.Entry entry = (Map.Entry) entryIter.next();
+    	this.put(entry.getKey(),entry.getValue());
+    }
+
   }
 
   public TypedTreeMap(SortedMap smap, Cast keyCast, Cast valueCast)
   {
-    super(smap);
+    super(smap.comparator());
 
     this.keyCast = keyCast;
     this.valueCast = valueCast;
+
+    Iterator entryIter = smap.entrySet().iterator();
+    while (entryIter.hasNext()) {
+	Map.Entry entry = (Map.Entry) entryIter.next();
+	this.put(entry.getKey(),entry.getValue());
+    }
+
   }
 
   public Cast getKeyCast()
Index: utils.txt
===================================================================
RCS file: /cvsroot/sablecc/sablecc/src/org/sablecc/sablecc/utils.txt,v
retrieving revision 1.4
diff -u -r1.4 utils.txt
--- utils.txt	20 Mar 2003 03:50:57 -0000	1.4
+++ utils.txt	26 Mar 2003 09:16:51 -0000
@@ -369,9 +369,9 @@
 
     public TypedLinkedList(Collection c)
     {
-        super(c);
-
+        super();
         cast = NoCast.instance;
+        this.addAll(c);
     }
 
     public TypedLinkedList(Cast cast)
@@ -383,9 +383,9 @@
 
     public TypedLinkedList(Collection c, Cast cast)
     {
-        super(c);
-
+        super();
         this.cast = cast;
+        this.addAll(c);
     }
 
     public Cast getCast()