This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Reflection and TreeMap fixes


Okay, with these fixes applied, Kaffe's MapTest runs perfectly ;-)

Incidently, in the TreeMap.iterator() case, where you do something
like:

Map tm = new TreeMap();
Iterator itr = tm.iterator();
tm.add("foo","bar")
itr.next();

The spec does not afaik specify whether a
ConcurrentModificationExcepti0n or NoSuchElementException should be
thrown. Both apply, and I would have thought Concurrent would be more
logical, but it turns out the JDK throws the NoSuchElementException,
so I have changed the TreeMap impl to match this.

regards

  [ bryce ]


2001-02-14  Bryce McKinlay  <bryce@albatross.co.nz>

	* java/lang/natClass.cc (getSignature): Don't try to dereference 
	param_types if it is null. Instead, take this to mean "no parameters".
	* java/lang/TreeMap.java (TreeIterator.next): Throw 
	NoSuchElementException in preference to ConcurrentModificationException.
	(TreeIterator.remove): Throw IllegalStateException in preference to 
	ConcurrentModificationException.
	(SubMap.firstKey): Do a better check for empty SubMap, and if it is,
	throw a NoSuchElementException.
	(SubMap.lastKey): Likewise.

Index: java/lang/natClass.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/lang/natClass.cc,v
retrieving revision 1.36
diff -u -r1.36 natClass.cc
--- natClass.cc	2001/02/08 01:49:53	1.36
+++ natClass.cc	2001/02/14 05:20:22
@@ -290,8 +290,12 @@
   java::lang::StringBuffer *buf = new java::lang::StringBuffer ();
   buf->append((jchar) '(');
   jclass *v = elements (param_types);
-  for (int i = 0; i < param_types->length; ++i)
-    v[i]->getSignature(buf);
+  // A NULL param_types means "no parameters".
+  if (param_types != NULL)
+    {
+      for (int i = 0; i < param_types->length; ++i)
+	v[i]->getSignature(buf);
+    }
   buf->append((jchar) ')');
   if (is_constructor)
     buf->append((jchar) 'V');
Index: java/util/TreeMap.java
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/util/TreeMap.java,v
retrieving revision 1.1
diff -u -r1.1 TreeMap.java
--- TreeMap.java	2001/02/14 04:44:21	1.1
+++ TreeMap.java	2001/02/14 05:20:23
@@ -1194,10 +1194,10 @@
 
     public Object next()
     {
-      if (knownMod != TreeMap.this.modCount)
-	throw new ConcurrentModificationException();
       if (next == nil)
 	throw new NoSuchElementException();
+      if (knownMod != TreeMap.this.modCount)
+	throw new ConcurrentModificationException();
       Node n = next;
 
       // Check limit in case we are iterating through a submap.
@@ -1217,11 +1217,10 @@
 
     public void remove()
     {
-      if (knownMod != TreeMap.this.modCount)
-	throw new ConcurrentModificationException();
-
       if (last == null)
 	throw new IllegalStateException();
+      if (knownMod != TreeMap.this.modCount)
+	throw new ConcurrentModificationException();
 /*
       Object key = null;
       if (next != nil)
@@ -1408,19 +1407,17 @@
     public Object firstKey()
     {
       Node node = lowestGreaterThan(minKey);
-      // Do a range check in case SubMap is empty.
-      if (keyInRange(node.key))
-        return node.key;
-      return null;
+      if (node == nil || !keyInRange(node.key))
+        throw new NoSuchElementException ("empty");
+      return node.key;
     }
 
     public Object lastKey()
     {
       Node node = highestLessThan(maxKey);
-      // Do a range check in case SubMap is empty.
-      if (keyInRange(node.key))
-        return node.key;
-      return null;
+      if (node == nil || !keyInRange(node.key))
+        throw new NoSuchElementException ("empty");
+      return node.key;
     }
 
     public SortedMap subMap(Object fromKey, Object toKey)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]