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

java.net.Socket.close does not throw IOException on second close

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5

    Description



      Name: yyC67448 Date: 09/30/97



      The java.net.Socket.close() does not throw IOException when
      closing already closed socket.

      Here is the test demonstrating the bug:

      -------------------------------- Test.java -----------------------------
      import java.io.*;
      import java.net.*;


      class test
      {

        public static void main(String args[])
        {
          InetAddress sin = null;
          Socket soc = null;
          int value = 0;


          /*
           * Try to get localhost address
           */
          try {
            sin = InetAddress.getLocalHost();
          } catch(Exception e)
          {
            System.out.println("Can not get localhost Address:" + e);
            System.exit(-1);
          }


          /*
           * Hope Telnet service enabled on localhost.
           */
          try {
            soc = new Socket(sin, 23, true);
          } catch(Exception e)
          {
            System.out.println("Can not create socket:" + e);
            System.exit(-1);
          }

          /*
           * Try to close socket
           */
          try {
            soc.close();
          } catch(Exception e)
          {
      System.out.println("Can not close socket first time:" + e);
      System.exit(-1);
          }

          /*
           * Try to close once more...
           */
          try {
            soc.close();
          } catch(IOException 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.
      -----------------------------------------------------------------

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

      Attachments

        Activity

          People

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: