changeset 10646:99230080fada

8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack Reviewed-by: michaelm
author chegar
date Fri, 12 Sep 2014 15:51:22 +0100
parents 1ebd76247e3e
children 42cf719516d0
files src/java.base/windows/native/libnet/NetworkInterface.c test/java/net/NetworkInterface/Test.java
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/windows/native/libnet/NetworkInterface.c	Fri Sep 12 12:19:27 2014 +0200
+++ b/src/java.base/windows/native/libnet/NetworkInterface.c	Fri Sep 12 15:51:22 2014 +0100
@@ -990,9 +990,11 @@
       case MIB_IF_TYPE_FDDI:
       case IF_TYPE_IEEE80211:
         len = ifRowP->dwPhysAddrLen;
-        ret = (*env)->NewByteArray(env, len);
-        if (!IS_NULL(ret)) {
-          (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr);
+        if (len > 0) {
+            ret = (*env)->NewByteArray(env, len);
+            if (!IS_NULL(ret)) {
+              (*env)->SetByteArrayRegion(env, ret, 0, len, (jbyte *) ifRowP->bPhysAddr);
+            }
         }
         break;
       }
--- a/test/java/net/NetworkInterface/Test.java	Fri Sep 12 12:19:27 2014 +0200
+++ b/test/java/net/NetworkInterface/Test.java	Fri Sep 12 15:51:22 2014 +0100
@@ -22,7 +22,9 @@
  */
 
 /* @test
- * @bug 4405354 6594296
+ * @bug 4405354 6594296 8058216
+ * @run main Test
+ * @run main/othervm -Djava.net.preferIPv4Stack=true Test
  * @summary Basic tests for NetworkInterface
  */
 import java.net.NetworkInterface;