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

Socket.getOption(SocketOption) not returning the expected type for the StandardSocketOptions.SO_LINGER

XMLWordPrintable

    • b24

        Socket.getOption(StandardSocketOptions.SO_LINGER) does not return the
        expected type, when invoked on a socket that has not had its setOption
        equivalent invoke to set the option. The expected returned type is
        Integer, but the actual type is Boolean.

        For example:

          $ jdk-12.jdk/Contents/Home/bin/jshell
          | Welcome to JShell -- Version 12
          | For an introduction type: /help intro
          
          jshell> var s = new Socket()
          s ==> Socket[unconnected]

          jshell> s.getOption(StandardSocketOptions.SO_LINGER)
          | Exception java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class java.lang.Integer (java.lang.Boolean and java.lang.Integer are in module java.base of loader 'bootstrap')
          | at (#2:1)

        ---

        There are also issues when negative values are set. For example:

          jshell> var s = new Socket()
          s ==> Socket[unconnected]

          jshell> s.setOption(StandardSocketOptions.SO_LINGER, -1)
          $4 ==> Socket[unconnected]

          jshell> s.getOption(StandardSocketOptions.SO_LINGER)
          $5 ==> 65535

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

                Created:
                Updated:
                Resolved: