RFR 9: MulticastSendReceiveTests.java fails with NumberFormatException
Chris Hegarty
chris.hegarty at oracle.com
Wed Mar 25 12:16:38 UTC 2015
This is a trivial test only one-liner. The test should attempt to
reconstruct the String message with the same charset as is used to
convert the original message to bytes, UTF-8.
The following exception was seen during testing (because of this bug):
java.lang.NumberFormatException: For input string:
"\u0001\u0002\u0003\u0005"
at
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:567)
at java.lang.Integer.parseInt(Integer.java:699)
at
MulticastSendReceiveTests.receiveDatagram(MulticastSendReceiveTests.java:112)
at
MulticastSendReceiveTests.test(MulticastSendReceiveTests.java:182)
at
MulticastSendReceiveTests.main(MulticastSendReceiveTests.java:245)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:502)
at
com.sun.javatest.regtest.MainAction$SameVMRunnable.run(MainAction.java:776)
at java.lang.Thread.run(Thread.java:745)
---
Fix:
diff --git
a/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
b/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
--- a/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
+++ b/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java
@@ -109,7 +109,7 @@
buf.flip();
byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
- int receivedId = Integer.parseInt(new String(bytes));
+ int receivedId = Integer.parseInt(new String(bytes,
"UTF-8"));
System.out.format("Received message from %s (id=0x%x)\n",
sender, receivedId);
-Chris.
More information about the nio-dev
mailing list