InetAddress.java (InetAddress): Make a private copy of the address.

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
This commit is contained in:
David Daney 2005-02-03 17:44:20 +00:00 committed by David Daney
parent 773af5d0df
commit 4dc2f71b90
4 changed files with 20 additions and 7 deletions

View 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.

View File

@ -207,7 +207,7 @@ public final class Inet4Address extends InetAddress
*/
public byte[] getAddress()
{
return addr;
return (byte[]) addr.clone();
}
/**

View 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);
}
/**

View 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)