]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
InetAddress.java (InetAddress): Make a private copy of the address.
authorDavid Daney <ddaney@avtrex.com>
Thu, 3 Feb 2005 17:44:20 +0000 (17:44 +0000)
committerDavid Daney <daney@gcc.gnu.org>
Thu, 3 Feb 2005 17:44:20 +0000 (17:44 +0000)
2005-02-02  David Daney  <ddaney@avtrex.com>

* java/net/InetAddress.java (InetAddress): Make a private copy of
the address.
* java/net/Inet4Address.java (getAddress): Return a copy of the
address.
* java/net/Inet6Address.java (Inet6Address): Use private copy of
the address
(getAddress): Return a copy of the address.
(equals): Rewrote.

From-SVN: r94664

libjava/ChangeLog
libjava/java/net/Inet4Address.java
libjava/java/net/Inet6Address.java
libjava/java/net/InetAddress.java

index b7d1c39ca93bda25def15ffdb1e9f494bfad0c83..1ee4076912b53fb21d5b1593df5c52c16cbef6b6 100644 (file)
@@ -1,3 +1,14 @@
+2005-02-02  David Daney  <ddaney@avtrex.com>
+
+       * java/net/InetAddress.java (InetAddress): Make a private copy of
+       the address.
+       * java/net/Inet4Address.java (getAddress): Return a copy of the
+       address.
+       * java/net/Inet6Address.java (Inet6Address): Use private copy of
+       the address
+       (getAddress): Return a copy of the address.
+       (equals): Rewrote.
+
 2005-02-02  Tom Tromey  <tromey@redhat.com>
 
        * Makefile.in: Rebuilt.
index 917e9e3e667d74e4eeae8d85f8d82d5b227537b1..b654ce6cddb431f2976d5cf69f4631d8c9976abf 100644 (file)
@@ -207,7 +207,7 @@ public final class Inet4Address extends InetAddress
    */
   public byte[] getAddress()
   {
-    return addr;
+    return (byte[]) addr.clone();
   }
 
   /**
index 0c1d60e8edf8dedadf98a76d46b95b4099c27af0..69d266a4c1764c18d451adba3be5a3cfea18fd92 100644 (file)
@@ -65,7 +65,8 @@ public final class Inet6Address extends InetAddress
   Inet6Address(byte[] addr, String host)
   {
     super(addr, host);
-    this.ipaddress = addr;
+    // Super constructor clones the addr.  Get a reference to the clone.
+    this.ipaddress = this.addr;
   }
 
   /**
@@ -194,7 +195,7 @@ public final class Inet6Address extends InetAddress
    */
   public byte[] getAddress()
   {
-    return ipaddress;
+    return (byte[]) ipaddress.clone();
   }
 
   /**
@@ -233,9 +234,10 @@ public final class Inet6Address extends InetAddress
     if (! (obj instanceof Inet6Address))
       return false;
 
-    Inet6Address tmp = (Inet6Address) obj;
-
-    return super.equals(tmp) && this.ipaddress == tmp.ipaddress;
+    // this.ipaddress is never set in this class except to
+    // the value of the super class' addr.  The super classes
+    // equals(Object) will do the compare.
+    return super.equals(obj);
   }
 
   /**
index cfcf22b42682745498b3975d6295cebde1b6c868..5a3ec474cf9e6d9816f36e6d227bc587e73415a0 100644 (file)
@@ -123,7 +123,7 @@ public class InetAddress implements Serializable
    */
   InetAddress(byte[] ipaddr, String hostname)
   {
-    addr = ipaddr;
+    addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
     hostName = hostname;
     
     if (ipaddr != null)