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

DataOuputStream should clarify that it might write primitive types as multiple byte groups

XMLWordPrintable

    • b07
    • generic
    • generic

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      All OS

      A DESCRIPTION OF THE PROBLEM :
      DataOutputSteam function writeInt() should create a 4 byte packet but instead creates 2 packets. 1 is a 1 byte packet and then it is followed by a 3 byte packet.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use wireshark to monitor packets being sent by server to client through writeInt(). Compare with writeLong().

      Source code attached is two separate programs, one for server and one for client.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      //Server source code
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.net.ServerSocket;
      import java.net.Socket;
      import java.util.Date;
      import java.io.DataOutputStream;


      public class TestServer {

          /**
           * Runs the server.
           */
          public static void main(String[] args) throws Exception {
              ServerSocket listener = new ServerSocket(11000);
              int len = 13421772;
              long lon = 500000000;

              try {
                  while (true) {
                      Socket socket = listener.accept();
                      try {

                          DataOutputStream dataOut = new DataOutputStream(socket.getOutputStream());

                          dataOut.writeInt(len);

                          dataOut.flush();


                      } finally {
                          socket.close();
                      }
                  }
              }
              finally {
                  listener.close();
              }
          }
      }
      ===================================

      //Client source code
      import java.io.BufferedReader;
      import java.io.IOException;
      import java.io.InputStreamReader;
      import java.net.Socket;


      public class TestClient {

          public static void main(String[] args) throws IOException {
              String serverAddress = "9.41.222.238";
              Socket s = new Socket(serverAddress, 11000);

              BufferedReader getResponse =
                      new BufferedReader(new InputStreamReader(s.getInputStream()));
              String answer = getResponse.readLine();
              System.out.println("answer= " + answer);

              System.exit(0);
          }
      }
      ---------- END SOURCE ----------

        1. TestServer.java
          0.7 kB
        2. TestClient.java
          0.5 kB
        3. Long.JPG
          Long.JPG
          18 kB
        4. Int_2.JPG
          Int_2.JPG
          19 kB
        5. Int_1.JPG
          Int_1.JPG
          16 kB

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: