Arrays.java (equals(all variants)): Quit using NullPointerException catching to detec...
authorDavid Daney <ddaney@avtrex.com>
Wed, 10 Sep 2003 18:11:05 +0000 (18:11 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 10 Sep 2003 18:11:05 +0000 (18:11 +0000)
2003-09-10  David Daney <ddaney@avtrex.com>

* java/util/Arrays.java (equals(all variants)): Quit using
NullPointerException catching to detect null valued parameters.

From-SVN: r71275

libjava/ChangeLog
libjava/java/util/Arrays.java

index 9c3f9c1d9d6a0921976c8cd682842f571eb56237..11e054583b39ece278bc1487b77f4c190b9c2cc0 100644 (file)
@@ -1,3 +1,8 @@
+2003-09-10  David Daney <ddaney@avtrex.com>
+
+       * java/util/Arrays.java (equals(all variants)): Quit using
+       NullPointerException catching to detect null valued parameters.
+
 2003-09-10  Michael Koch  <konqueror@gmx.de>
 
        * java/net/DatagramSocket.java,
index 35e0e92ca599214541585de6cbc3fd1e3a6c1386..080b4b9cbf95004af5dec0123cf7186fd972dd9f 100644 (file)
@@ -1,5 +1,5 @@
 /* Arrays.java -- Utility class with methods to operate on arrays
-   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -398,23 +398,18 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
+    if (null == a1 || null == a2)
+      return false;
+    
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
-
     return false;
   }
 
@@ -433,21 +428,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    if (null == a1 || null == a2)
+      return false;
+
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
     return false;
   }
@@ -467,21 +458,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
+    if (null == a1 || null == a2)
+      return false;
+    
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
     return false;
   }
@@ -501,21 +488,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    if (null == a1 || null == a2)
+      return false;
+
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
     return false;
   }
@@ -535,21 +518,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    if (null == a1 || null == a2)
+      return false;
+
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
     return false;
   }
@@ -569,21 +548,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (a1[i] != a2[i])
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    if (null == a1 || null == a2)
+      return false;
+
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (a1[i] != a2[i])
+           return false;
+       return true;
       }
     return false;
   }
@@ -603,22 +578,18 @@ public class Arrays
     if (a1 == a2)
       return true;
 
+    if (null == a1 || null == a2)
+      return false;
+
     // Must use Float.compare to take into account NaN, +-0.
-    try
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (Float.compare(a1[i], a2[i]) != 0)
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
-      {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (Float.compare(a1[i], a2[i]) != 0)
+           return false;
+       return true;
       }
     return false;
   }
@@ -638,22 +609,18 @@ public class Arrays
     if (a1 == a2)
       return true;
 
+    if (null == a1 || null == a2)
+      return false;
+    
     // Must use Double.compare to take into account NaN, +-0.
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (Double.compare(a1[i], a2[i]) != 0)
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (Double.compare(a1[i], a2[i]) != 0)
+           return false;
+       return true;
       }
     return false;
   }
@@ -674,21 +641,17 @@ public class Arrays
     if (a1 == a2)
       return true;
 
-    try
-      {
-        // If they're the same length, test each element
-        if (a1.length == a2.length)
-          {
-            int i = a1.length;
-            while (--i >= 0)
-              if (! AbstractCollection.equals(a1[i], a2[i]))
-                return false;
-            return true;
-          }
-      }
-    catch (NullPointerException e)
+    if (null == a1 || null == a2)
+      return false;
+    
+    // If they're the same length, test each element
+    if (a1.length == a2.length)
       {
-        // If one is null, we get a harmless NullPointerException
+       int i = a1.length;
+       while (--i >= 0)
+         if (! AbstractCollection.equals(a1[i], a2[i]))
+           return false;
+       return true;
       }
     return false;
   }