diff --git a/src/windows/native/java/net/NetworkInterface_winXP.c b/src/windows/native/java/net/NetworkInterface_winXP.c index ce0206be022effdbd4297bd6fd1f1cf2d37baa84..1078d826afa9891ffe37910927f7ad26587d33f4 100644 --- a/src/windows/native/java/net/NetworkInterface_winXP.c +++ b/src/windows/native/java/net/NetworkInterface_winXP.c @@ -818,10 +818,12 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0_XP ptr = getAdapter(env, index); if (ptr != NULL) { len = ptr->PhysicalAddressLength; - ret = (*env)->NewByteArray(env, len); - if (!IS_NULL(ret)) { - (*env)->SetByteArrayRegion(env, ret, 0, len, - (jbyte*) ptr->PhysicalAddress); + if (len > 0) { + ret = (*env)->NewByteArray(env, len); + if (!IS_NULL(ret)) { + (*env)->SetByteArrayRegion(env, ret, 0, len, + (jbyte*) ptr->PhysicalAddress); + } } free(ptr); } diff --git a/test/java/net/NetworkInterface/Test.java b/test/java/net/NetworkInterface/Test.java index 70b9201d7233c1b54cb8f843b33f5634299e4f43..74033c195cc431043f50077e972ef9753f4e766d 100644 --- a/test/java/net/NetworkInterface/Test.java +++ b/test/java/net/NetworkInterface/Test.java @@ -21,9 +21,9 @@ * questions. */ -/* @test 01/02/14 - * @bug 4405354 - * @summary Exercise java.net.NetworkInterface +/* @test + * @bug 4405354 6594296 + * @summary Basic tests for NetworkInterface */ import java.net.NetworkInterface; import java.net.InetAddress; @@ -69,6 +69,12 @@ public class Test { throw new Exception("hashCode contract broken"); } System.out.println("hashCode() test passed."); + + byte[] ba = ni.getHardwareAddress(); + if (ba != null && ba.length == 0) { + throw new Exception("getHardwareAddress returned 0 length byte array"); + } + System.out.println("getHardwareAddress() test passed."); } // misc tests :-