United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7058336 (so) Socket adpator is not synchronized on channel state
JDK-7058336 : (so) Socket adpator is not synchronized on channel state

Details
Type:
Bug
Submit Date:
2011-06-23
Status:
Closed
Updated Date:
2012-01-26
Project Name:
JDK
Resolved Date:
2011-12-19
Component:
core-libs
OS:
linux_redhat_5.0
Sub-Component:
java.nio
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0u17
Fixed Versions:
6u30-rev (b22)

Related Reports
Backport:
Backport:
Backport:

Sub Tasks

Description
When a customer try to do some operation for closed SocketChannel, the exception message does not seem appropriate.

CONFIGURATION:
JDK5u17/RHEL5

TEST CASE:
-------------------------------------------------------------
 import java.nio.channels.*;

 public class TestSocket {
  public static void main(String[] args) throws Exception {
   SocketChannel sc = SocketChannel.open();
    sc.configureBlocking(false);
    Selector sel = Selector.open();
    sc.register(sel, 0);
    sel.selectNow();
    sc.close();
    sc.socket().setTcpNoDelay(false);
  }
 }
 -------------------------------------------------------------

REPRODUCE:
Compile the attached test case and run

The following message will show up.
java.net.SocketException: Operation not supported
	at sun.nio.ch.Net.setIntOption0(Native Method)
	at sun.nio.ch.Net.setIntOption(Net.java:152)
	at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:372)
	at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
	at sun.nio.ch.SocketOptsImpl$IP$TCP.noDelay(SocketOptsImpl.java:284)
	at sun.nio.ch.OptionAdaptor.setTcpNoDelay(OptionAdaptor.java:48)
	at sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:268)
	at com.sun.enterprise.web.connector.grizzly.SelectorThread.setSocketOptions(SelectorThread.java:1956)
	at com.sun.enterprise.web.connector.grizzly.SelectorThread.handleAccept(SelectorThread.java:1517)
        ....


"Operation not Supported" is EOPNOTSUPP.
So, the message,"Socket is closed" seems appropriate in this case
like the following result in jdk7.

----
Exception in thread "main" java.net.SocketException: Socket is closed
        at sun.nio.ch.Net.translateToSocketException(Net.java:105)
        at sun.nio.ch.SocketAdaptor.setBooleanOption(SocketAdaptor.java:288)
        at sun.nio.ch.SocketAdaptor.setTcpNoDelay(SocketAdaptor.java:321)
        at TestSocket.main(TestSocket.java:11)
Caused by: java.nio.channels.ClosedChannelException
        at sun.nio.ch.SocketChannelImpl.setOption(SocketChannelImpl.java:170)
        at sun.nio.ch.SocketAdaptor.setBooleanOption(SocketAdaptor.java:286)
        ... 2 more
------

                                    

Comments
EVALUATION

This bug is applicable to jdk6 and older. It is not applicable to jdk7 because the socket adpators were ssentially re-written in jdk7 as part of the socket-channel completion work. The basic issue in jdk6 and older is that the socket adpators aren't properly synchronized with the channel state. I've changed the synopsis of this bug to reflect the issue.
                                     
2011-06-23
EVALUATION

one solution is to check if the socketChannel is closed before getting/setting various parameters
                                     
2011-11-16



Hardware and Software, Engineered to Work Together