[kaffe] Arrays.equals

Daniel Bonniot Daniel.Bonniot@inria.fr
Wed May 21 17:17:01 2003


This is a multi-part message in MIME format.
--------------050804070902050403020006
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit


Arrays.equals in Kawa does not handle properly null elements. Here is a 
testcase (is this the correct format for Kawa's regression tests?)

import java.util.*;

public class ArraysTest
{
  public static void main(String[] args)
  {
    final String[] a1 = { "", null };
    final String[] a2 = { "", null };

    System.out.println(Arrays.equals(a1, a2));
  }
}

/* Expected Output:
true
*/

Kawa CVS prints false. I attach a patch that fixes this problem.

A note about source code formatting. It seems that the convention in 
Kawa is to use tabs for indentation (although this is not documented, see
http://www.kaffe.org/doc/kaffe/FAQ.coding-style).
I usually use Emacs, and the JDEE to edit Java sources. A useful feature 
of this emacs mode is that you can set up preferences (notably 
indentation style) in a central project file. Maybe it would be useful 
to include such a file in CVS. It would both make it easier to edit the 
sources, and ensure a consistent formatting (for those using JDEE, of 
course). I attach a first attempt as prj.el (it should go to the 
toplevel directory). What do people think about this?

Daniel


--------------050804070902050403020006
Content-Type: text/plain;
 name="Arrays.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Arrays.diff"

Index: ChangeLog
===================================================================
RCS file: /cvs/kaffe/kaffe/ChangeLog,v
retrieving revision 1.1339
diff -u -r1.1339 ChangeLog
--- ChangeLog	19 May 2003 08:01:20 -0000	1.1339
+++ ChangeLog	21 May 2003 23:52:55 -0000
@@ -1,3 +1,8 @@
+2003-05-22  Daniel Bonniot  <bonniot@users.sourceforge.net>
+
+	* libraries/javalib/java/util/Arrays: 
+	(equals(Object[], Object[])) fixed handling of null elements.
+
 2003-05-19  Gwenole Beauchesne  <gbeauchesne@mandrakesoft.com>
 
         Add support for Linux/AMD64.
Index: libraries/javalib/java/util/Arrays.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/Arrays.java,v
retrieving revision 1.7
diff -u -r1.7 Arrays.java
--- libraries/javalib/java/util/Arrays.java	22 Nov 2001 06:21:17 -0000	1.7
+++ libraries/javalib/java/util/Arrays.java	21 May 2003 23:53:52 -0000
@@ -285,19 +285,29 @@
   }
 
   public static boolean equals(Object[] a, Object[] a2) {
-	try {
+		if (a == a2) {
+			return true;
+		}
+
+		if (a == null || a2 == null) {      
+			return false; // One is null and not the other.
+		}
+
 		if (a.length != a2.length) {
 			return false;
 		}
+
 		for (int i = a.length; i-- > 0; ) {
-			if (!a[i].equals(a2[i])) {
+			if (a[i] == null) {
+				if (a2[i] != null) {
+					return false;
+				}
+			} else if (!a[i].equals(a2[i])) {
 				return false;
 			}
 		}
+
 		return true;
-	} catch (NullPointerException _) {
-		return (a == a2);	// ie, they are both null
-	}
   }
 
   public static void fill(boolean[] a, boolean val) {

--------------050804070902050403020006
Content-Type: text/plain;
 name="prj.el"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="prj.el"

(jde-project-file-version "1.0")

;; Standard indentation settings for Java files in Kaffe.
(setq indent-tabs-mode t)
(setq tab-width 2)
(setq c-basic-offset 2)


--------------050804070902050403020006--