Hi Chris and Wyom,

    fixed as commented.  Updated webrev:

    http://cr.openjdk.java.net/~xiaofeya/8194260/webrev.01/

Thanks,
Felix
On 2018/4/17 16:25, Chris Hegarty wrote:
On 17 Apr 2018, at 04:34, Felix Yang <felix.y...@oracle.com> wrote:
...
     http://cr.openjdk.java.net/~xiaofeya/8194260/webrev.00/
Thanks for doing this Felix. Mainly looks good. Just a few comments.

The old test runs on systems without IPv4 or IPv6 configured. So
I think the Optional `get` should be replaced with `orElse`. Either that
or update usage to check for the presence of a value in the Optional.

The old test filters out the loopback address, in order to get “real”
addresses. I think we should preserve this behaviour. Other filtering
is done in the old tests too, but I don’t think it is really needed.

---
diff --git a/test/jdk/java/net/ipv6tests/Tests.java 
b/test/jdk/java/net/ipv6tests/Tests.java
--- a/test/jdk/java/net/ipv6tests/Tests.java
+++ b/test/jdk/java/net/ipv6tests/Tests.java
@@ -178,26 +178,28 @@
      }
public static Inet4Address getFirstLocalIPv4Address () {
-        return getNetworkConfig().ip4Addresses()
-                                 .findFirst()
-                                 .get();
+        return networkConfig.ip4Addresses()
+                             .filter(a -> !a.isLoopbackAddress())
+                             .findFirst()
+                             .orElse(null);
      }
public static Inet6Address getFirstLocalIPv6Address () {
-        return getNetworkConfig().ip6Addresses()
-                                 .findFirst()
-                                 .get();
+        return networkConfig.ip6Addresses()
+                             .filter(a -> !a.isLoopbackAddress())
+                             .findFirst()
+                             .orElse(null);
      }
+ private static NetworkConfiguration networkConfig = getNetworkConfig();
+
      private static NetworkConfiguration getNetworkConfig() {
-        NetworkConfiguration cfg = null;
          try {
-            cfg = NetworkConfiguration.probe();
+            return  NetworkConfiguration.probe();
          } catch (IOException e) {
              System.out.println("Failed to probe NetworkConfiguration");
              throw new RuntimeException(e);
          }
-        return cfg;
      }
-Chris.

Reply via email to