From 30790d83529eeb2778fbd5ad62a4eae0c04c9ce4 Mon Sep 17 00:00:00 2001 From: Mark Sheppard Date: Tue, 7 Mar 2017 22:35:45 +0000 Subject: [PATCH] 8175325: NetworkInterface.getInterfaceAddresses throws NPE when no addresses Reviewed-by: chegar, martin --- .../classes/java/net/NetworkInterface.java | 20 ++--- ...orkInterfaceEmptyGetInetAddressesTest.java | 78 +++++++++++++++++++ 2 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 jdk/test/java/net/MulticastSocket/NetworkInterfaceEmptyGetInetAddressesTest.java diff --git a/jdk/src/java.base/share/classes/java/net/NetworkInterface.java b/jdk/src/java.base/share/classes/java/net/NetworkInterface.java index 960024f939d..66141af44fa 100644 --- a/jdk/src/java.base/share/classes/java/net/NetworkInterface.java +++ b/jdk/src/java.base/share/classes/java/net/NetworkInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -175,14 +175,16 @@ public final class NetworkInterface { */ public java.util.List getInterfaceAddresses() { java.util.List lst = new java.util.ArrayList<>(1); - SecurityManager sec = System.getSecurityManager(); - for (int j=0; j 0) { + throw new RuntimeException("Unexpected Exceptions in test"); + } + } + + private static void testNetworkInterface_getInterfaceAddresses( + NetworkInterface netIf) { + try { + netIf.getInterfaceAddresses(); + } catch (Exception ex) { + ex.printStackTrace(); + incrementExceptionCount(); + } + } + + private static void incrementExceptionCount() { + exceptionCount++; + } + + public static void main(String[] args) throws Exception { + MulticastSocket mcastSock = null; + try { + mcastSock = new MulticastSocket(); + System.out.println("macst socket address == " + + mcastSock.getLocalAddress()); + NetworkInterface netIf = mcastSock.getNetworkInterface(); + testMethods(netIf); + } finally { + if (mcastSock != null) { + mcastSock.close(); + } + } + } +}