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

UnsupportedOperationException is not thrown for unsupported options

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b10
    • Introduced In Version:
      9
    • Resolved In Build:
      b102
    • OS:
      solaris_11
    • Verification:
      Verified

      Description

      SO_FLOW_SLA option is not supported for ServerSocket on any platform, but UnsupportedOperationException is not thrown if we try to set or get SO_FLOW_SLA option for ServerSocket on Solaris 11.2

      To reproduce this problem please run next code on Solaris 11.2 or later host:

      import jdk.net.ExtendedSocketOptions;
      import jdk.net.Sockets;
      import java.io.IOException;
      import java.net.ServerSocket;

      public class Test {

          public static void main(String[] args) throws IOException {
              boolean isOptionSupported = Sockets.supportedOptions(ServerSocket.class)
                      .contains
                              (ExtendedSocketOptions.SO_FLOW_SLA);
              System.out.println("SO_FLOW_SLA supported: " + isOptionSupported);
              Sockets.getOption(new ServerSocket(), ExtendedSocketOptions
                      .SO_FLOW_SLA);
          }
      }

      Expected:
      SO_FLOW_SLA supported: false
      Exception in thread "main" java.lang.UnsupportedOperationException: SO_FLOW_SLA
              at jdk.net.Sockets.getOption(Sockets.java:262)
              at Test.main(Test.java:19)

      Got:
      SO_FLOW_SLA supported: false
      Exception in thread "main" java.net.SocketException: set option SO_FLOW_SLA failed
              at sun.net.ExtendedOptionsImpl.getFlowOption(Native Method)
              at java.net.PlainSocketImpl.getOption(PlainSocketImpl.java:82)
              at java.net.ServerSocket.getOption(ServerSocket.java:980)
              at jdk.net.Sockets.getOption(Sockets.java:172)
              at Test.main(Test.java:19)

      Cause:
      jdk 8 implementation contains check for getOption and setOption. e.g.:
      public static <T> void setOption(Socket s, SocketOption<T> name, T value) throws IOException
       {
           if (!isSupported(Socket.class, name)) {
                  throw new UnsupportedOperationException(name.name());
          }
       invokeSet(siSetOption, s, name, value);
       }

      while in jdk 9 setOption and getOption of Sockets classes:

         public static <T> void setOption(ServerSocket s, SocketOption<T> name, T value) throws IOException
          {
              s.setOption(name, value);
          } .

      where ServerSockets's (and other Socket's as well) setOption and getOption methods don't contain that check.

      Suggested fix:

      Add check to ServerSocket.java, Socket.java, DatagramSocket.java setOption and getOption methods.
          


        Attachments

          Issue Links

            Activity

              People

              Assignee:
              snikandrova Svetlana Nikandrova (Inactive)
              Reporter:
              snikandrova Svetlana Nikandrova (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: