Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8076644

(dc) MulticastSendReceiveTests.java fails with NumberFormatException due to network interference

    XMLWordPrintable

Details

    • b59

    Backports

      Description

        MulticastSendReceiveTests.java should ignore interference on the network. When the received bytes are not parseable into an Integer, expected id, the packet should be ignored and the test should continue. Additionally, 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)

        ---
        Proposed changes:

        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
                        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)

        Attachments

          Issue Links

            Activity

              People

                chegar Chris Hegarty
                chegar Chris Hegarty
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: