8058216: NetworkInterface.getHardwareAddress can return zero length byte array when run with preferIPv4Stack
Reviewed-by: michaelm
--- a/jdk/src/java.base/windows/native/libnet/NetworkInterface.c Fri Sep 12 12:19:27 2014 +0200
+++ b/jdk/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/jdk/test/java/net/NetworkInterface/Test.java Fri Sep 12 12:19:27 2014 +0200
+++ b/jdk/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;