RFR 9: MulticastSendReceiveTests.java fails with NumberFormatException
Chris Hegarty
chris.hegarty at oracle.com
Wed Mar 25 14:41:30 UTC 2015
Updated diffs based on an offline conversation with Alan.
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
@@ -97,7 +97,7 @@
// no datagram received
if (sa == null) {
if (expectedSender != null) {
- throw new RuntimeException("Expected message
not recieved");
+ throw new RuntimeException("Expected message
not received");
}
System.out.println("No message received (correct)");
return;
@@ -109,10 +109,15 @@
buf.flip();
byte[] bytes = new byte[buf.remaining()];
buf.get(bytes);
- int receivedId = Integer.parseInt(new String(bytes));
-
- System.out.format("Received message from %s (id=0x%x)\n",
- sender, receivedId);
+ String s = new String(bytes, "UTF-8");
+ int receivedId = -1;
+ try {
+ receivedId = Integer.parseInt(s);
+ System.out.format("Received message from %s
(id=0x%x)\n",
+ sender, receivedId);
+ } catch (NumberFormatException x) {
+ System.out.format("Received message from %s
(msg=%s)\n", sender, s);
+ }
if (expectedSender == null) {
if (receivedId == id)
-Chris.
On 25/03/15 14:26, Chris Hegarty wrote:
> On 25/03/15 12:36, Alan Bateman wrote:
>> On 25/03/2015 12:16, Chris Hegarty wrote:
>>> 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 fix looks okay and matches the sender. That said, it's possible that
>> this is just interference on the network too, in which case the package
>> should be ignored as is does already when it doesn't match the
>> expected id.
>
> Ah right. So, maybe the test should ignore data that cannot be parsed,
> so then it can continue to try to read the expected id. The current code
> cannot do this.
>....
>
> -Chris.
>
>> -Alan
More information about the nio-dev
mailing list