On 14/07/2010 12:35, Mark Hindess wrote:
In message<20100714103700.1592f2388...@eris.apache.org>, odea...@apache.org
writes:
Author: odeakin
Date: Wed Jul 14 10:36:59 2010
New Revision: 964001
URL: http://svn.apache.org/viewvc?rev=964001&view=rev
Log:
To match the RI's behaviour, resolve and store the hostname when getHostName
is called. Add a flag so we do not resolve the hostname for every call to get
HostName. Also add a regression test for the behaviour.
[SNIP]
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org
/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org
/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java Wed Jul 14 10:
36:59 2010
@@ -31,7 +31,9 @@ public class InetSocketAddressTest exten
public void test_ConstructorLjava_lang_StringI() throws Exception {
// regression test for Harmony-1042
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 0);
- assertNotNull(address.getHostName());
+ assertEquals("/127.0.0.1:0", address.toString());
+ assertEquals("localhost", address.getHostName());
+ assertEquals("localhost/127.0.0.1:0", address.toString());
}
/**
I would have assumed that the removed:
assertNotNull(address.getHostName());
was not:
assertEquals("localhost", address.getHostName());
for good reasons[0].
Ok - I hadn't realised that the local host name could be something
different on different machines (it's not a case I've come across) so
I'm happy to go with the approach below. I've applied the change at r964012.
Regards,
Oliver
Therefore it might be better to make the new code:
assertEquals("/127.0.0.1:0", address.toString());
String localhostName = address.getHostName();
assertNotNull(localhostName);
assertEquals(localhostName+"/127.0.0.1:0", address.toString());
or something like that?
Regards,
Mark.
[0] Such as "localhost" being a rather arbitrary string that may be
different on different machines? Some older Debian machines
have "localhost.localdomain" first in their /etc/hosts entries IIRC.
--
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU