6594296: NetworkInterface.getHardwareAddress returns zero length byte array
Reviewed-by: alanb
--- a/jdk/src/windows/native/java/net/NetworkInterface_winXP.c Tue Apr 30 17:51:31 2013 -0700
+++ b/jdk/src/windows/native/java/net/NetworkInterface_winXP.c Wed May 01 10:03:39 2013 +0100
@@ -818,10 +818,12 @@
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);
}
--- a/jdk/test/java/net/NetworkInterface/Test.java Tue Apr 30 17:51:31 2013 -0700
+++ b/jdk/test/java/net/NetworkInterface/Test.java Wed May 01 10:03:39 2013 +0100
@@ -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 @@
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 :-