From 29456fb8708444ebfa8d4fb7e660da171c813cac Mon Sep 17 00:00:00 2001
From: Eric Blake <ebb9@email.byu.edu>
Date: Fri, 3 Jan 2003 17:00:03 +0000
Subject: [PATCH] TreeMap.java (fabricateTree): Fix off-by-one error.

2003-01-03  Eric Blake  <ebb9@email.byu.edu>

	* java/util/TreeMap.java (fabricateTree): Fix off-by-one error.
	(TreeIterator.remove): Prefer IllegalStateException over
	ConcurrentModificationException, to match Sun.

From-SVN: r60837
---
 libjava/ChangeLog              | 6 ++++++
 libjava/java/util/TreeMap.java | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index a599abda672d..6b07d3fcc4f1 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,9 @@
+2003-01-03  Eric Blake  <ebb9@email.byu.edu>
+
+	* java/util/TreeMap.java (fabricateTree): Fix off-by-one error.
+	(TreeIterator.remove): Prefer IllegalStateException over
+	ConcurrentModificationException, to match Sun.
+
 2002-12-22  Anthony Green  <green@redhat.com>
 
 	* boehm.cc (_Jv_MarkObj): Mark the protectionDomain of a class.
diff --git a/libjava/java/util/TreeMap.java b/libjava/java/util/TreeMap.java
index dfa9bc638812..e0cff28e02c6 100644
--- a/libjava/java/util/TreeMap.java
+++ b/libjava/java/util/TreeMap.java
@@ -865,7 +865,7 @@ public class TreeMap extends AbstractMap
     int rowsize;
 
     // Fill each row that is completely full of nodes.
-    for (rowsize = 2; rowsize + rowsize < count; rowsize <<= 1)
+    for (rowsize = 2; rowsize + rowsize <= count; rowsize <<= 1)
       {
         Node parent = row;
         Node last = null;
@@ -1468,10 +1468,10 @@ public class TreeMap extends AbstractMap
      */
     public void remove()
     {
-      if (knownMod != modCount)
-        throw new ConcurrentModificationException();
       if (last == null)
         throw new IllegalStateException();
+      if (knownMod != modCount)
+        throw new ConcurrentModificationException();
 
       removeNode(last);
       last = null;
-- 
GitLab