JDK-8143554 : UnsupportedOperationException is not thrown for unsupported options
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_11
  • Submitted: 2015-11-20
  • Updated: 2016-08-24
  • Resolved: 2016-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b102Fixed
Related Reports
Relates :  
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.
    



Comments
Updated descriptions. As this issue was firstly found with SO_FLOW_SLA option, another SocketOptions are also affected. Also affected: ServerSocket Option: SO_SNDBUF ServerSocket Option: TCP_NODELAY ServerSocket Option: SO_LINGER ServerSocket Option: SO_KEEPALIVE
02-12-2015

Simple fix by adding check if option is supported like it was done in jdk 8 and jdk 7's Sockets class caused new test failure of the regression test test/java/net/SocketOption/OptionsTest.java Test exposed another problem with supported options: JDK-8143923
27-11-2015