changeset 10012:fdb6ac617320

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 8375459f193f
children fab04dd17d8d
files src/windows/native/java/net/NetworkInterface.c test/java/net/NetworkInterface/Test.java
diffstat 2 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/native/java/net/NetworkInterface.c	Fri Sep 12 15:17:05 2014 +0400
+++ b/src/windows/native/java/net/NetworkInterface.c	Fri Sep 12 15:51:22 2014 +0100
@@ -1014,9 +1014,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 15:17:05 2014 +0400
+++ 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;