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

java.net.Socket.setReceiveBufferSize(size) does not throw IAE with 0

    Details

    • Subcomponent:
    • Resolved In Build:
      ladybird
    • CPU:
      x86, sparc
    • OS:
      solaris_2.6, windows_2000

      Backports

        Description



        Name: dfC67450 Date: 03/30/2000



        Javadoc for java.net.Socket.setReceiveBufferSize(size) states:

             * @exception IllegalArgumentException if the value is 0 or is
             * negative.


        But method throws SocketException instead of IllegalArgumentException and throws
        IllegalArgumentException only if negative size passed.
        Source for java.net.Socket:

            public synchronized void setReceiveBufferSize(int size)
            throws SocketException{
        if (size < 0) {
        throw new IllegalArgumentException("invalid receive size");
        }
        impl.setOption(SocketOptions.SO_RCVBUF, new Integer(size));
            }

        Here is the test demonstrating the bug:
        ---------------------------------------------
        import java.net.*;
        import java.io.*;


        public class TestIAE {

            public static void main (String args[]){
               

                try {
                    ServerSocket server = new ServerSocket(0);
                    int port = server.getLocalPort();
                    InetAddress address = server.getInetAddress();

                    Socket soc = new Socket(address, port);
                    try {
                        soc.setReceiveBufferSize(0);
                    } catch (IllegalArgumentException iae) {
                        soc.close();
                        server.close();
                        System.out.println("Test passed");
                        return;
                    }
                    System.out.println("No exceptions");
                    
                } catch (Exception e) {
                    System.out.println(" " + e);
                }
                System.out.println(" Test failed");

            }
        }


        ------------- output from the test ---------

          java.net.SocketException: bad parameter for SO_SNDBUF or SO_RCVBUF
          Test failed
        ---------------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  jccollet Jean-Christophe Collet (Inactive)
                  Reporter:
                  fdasunw Fda Fda (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: