From 5f40c1642e061aae48cbd7b44b05aa49b74ad9a6 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 18 Dec 2013 10:12:10 -0700 Subject: [PATCH] don't throw UnknownHostException from InetAddress.getByName("0.0.0.0") 0.0.0.0 means any local interface, which is commonly used by servers which wish to listen on all interfaces. --- classpath/java/net/InetAddress.java | 3 --- classpath/java/util/Arrays.java | 18 ++++++++++++++++++ test/Misc.java | 6 +++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/classpath/java/net/InetAddress.java b/classpath/java/net/InetAddress.java index d0030d0469..39a4aa3dc5 100644 --- a/classpath/java/net/InetAddress.java +++ b/classpath/java/net/InetAddress.java @@ -19,9 +19,6 @@ public class InetAddress { private InetAddress(String name) throws UnknownHostException { this.name = name; this.ip = ipv4AddressForName(name); - if (ip == 0) { - throw new UnknownHostException(name); - } } public String getHostName() { diff --git a/classpath/java/util/Arrays.java b/classpath/java/util/Arrays.java index 9f2ef702c5..b978b5c5ff 100644 --- a/classpath/java/util/Arrays.java +++ b/classpath/java/util/Arrays.java @@ -286,6 +286,24 @@ public class Arrays { return true; } + public static boolean equals(byte[] a, byte[] b) { + if(a == b) { + return true; + } + if(a == null || b == null) { + return false; + } + if(a.length != b.length) { + return false; + } + for(int i = 0; i < a.length; i++) { + if(a[i] != b[i]) { + return false; + } + } + return true; + } + public static List asList(final T ... array) { return new AbstractList() { public int size() { diff --git a/test/Misc.java b/test/Misc.java index b0fde2d44b..0c91c5cb5b 100644 --- a/test/Misc.java +++ b/test/Misc.java @@ -135,7 +135,7 @@ public class Misc { } } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { zam(); Bim bim = new Baz(); @@ -287,6 +287,10 @@ public class Misc { } catch (IOException e) { throw new RuntimeException(e); } + + expect(java.util.Arrays.equals + (new byte[] { 0, 0, 0, 0 }, + java.net.InetAddress.getByName("0.0.0.0").getAddress())); } protected class Protected { }