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

DatagramSocket.setReceiveBufferSize does not throw IllegalArgumentException

XMLWordPrintable

    • beta
    • sparc
    • solaris_2.5



      Name: yyC67448 Date: 09/15/98




      The java.net.DatagramSocket.setReceiveBufferSize(int size) method does not
      throw IllegalArgumentException if size = 0;

      Here is the javadoc comment for this method:

      ---------------------------------

          /**
           * Sets the SO_RCVBUF option to the specified value for this
           * DatagramSocket. The SO_RCVBUF option is used by the platform's
           * networking code as a hint for the size to use to allocate set
           * the underlying network I/O buffers.
           *
           * <p>Increasing buffer size can increase the performance of
           * network I/O for high-volume connection, while decreasing it can
           * help reduce the backlog of incoming data. For UDP, this sets
           * the maximum size of a packet that may be sent on this socket.
           *
           * <p>Because SO_RCVBUF is a hint, applications that want to
           * verify what size the buffers were set to should call
           * <href="#getReceiveBufferSize>getReceiveBufferSize</a>.
           *
           * @param size the size to which to set the receive buffer
           * size. This value must be greater than 0.
           *
           * @exception IllegalArgumentException if the value is 0 or is
           * negative.
           */

      ---------------------------------


      Here is the test demonstrating the bug:

      ---------------------------- test.java --------------------------------
      import java.net.*;


      class test
      {

        public static void main(String args[])
        {
           DatagramSocket soc = null;
           
           try {
             soc = new DatagramSocket();
           } catch(Exception e)
           {
               System.out.println("Unexpected exception:" + e);
               System.exit(-1);
           }

           try {
              soc.setReceiveBufferSize(0);
           } catch(IllegalArgumentException e)
           {
      System.out.println("OKAY");
      System.exit(0);
           } catch(Exception e)
           {
      System.out.println("Unexpected exception:" + e);
      System.exit(-1);
           }

           System.out.println("No exceptions.");
            
        }
      }



      ---------------------- Output from the test -----------------
      No exceptions.
      -----------------------------------------------------------------


      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: