From 94dbab9120cc635a51a1368f43bbfed09643e9e8 Mon Sep 17 00:00:00 2001 From: Amy Lu Date: Fri, 8 May 2015 10:22:18 +0100 Subject: [PATCH] 8079651: (dc) Promiscuous.java fails with NumberFormatException due to network interference Reviewed-by: alanb, chegar --- .../nio/channels/DatagramChannel/Promiscuous.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jdk/test/java/nio/channels/DatagramChannel/Promiscuous.java b/jdk/test/java/nio/channels/DatagramChannel/Promiscuous.java index 884baaf581a..21c8c18440f 100644 --- a/jdk/test/java/nio/channels/DatagramChannel/Promiscuous.java +++ b/jdk/test/java/nio/channels/DatagramChannel/Promiscuous.java @@ -97,7 +97,7 @@ public class Promiscuous { // no datagram received if (sa == null) { if (datagramExepcted) { - 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 @@ public class Promiscuous { 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 (!datagramExepcted) { if (receivedId == id)