JDK-6842359 : (so) Socket adaptor getLocalPort method throws SocketException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6u13
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-05-18
  • Updated: 2014-02-25
  • Resolved: 2013-11-08
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.
6u75 b01Fixed
J2SE Version (please include all output from java -version flag):
java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

Does this problem occur on J2SE 5.0.x or 6.0?  Yes / No (pick one)

Operating System Configuration Information (be specific):
Client: Microsoft Windows XP [Version 5.1.2600]

Bug Description:

Error: java.net.SocketException: Socket operation on nonsocket: getsockname

Calling channel.socket().getLocalPort() can result in an Error.
The JavaDoc says: the local port number to which this socket is bound or -1 if the socket is not bound yet.
No Error should ever be thrown by this method.

java.lang.Error: java.net.SocketException: Socket operation on nonsocket: getsockname
	at sun.nio.ch.Net.localAddress(Net.java:125)
	at sun.nio.ch.SocketChannelImpl.localAddress(SocketChannelImpl.java:430)
	at sun.nio.ch.SocketAdaptor.getLocalPort(SocketAdaptor.java:159)

There's no regression test provided with the fix, as we don't have a clear recipe on how to reproduce the failure. The fix is a partial backport of the changes done in jdk7.

Esc issue to P2

EVALUATION The submitter has confirmed that the bug does not exist in jdk7. As there currently no plans to fix this one in jdk6 or earilier releases then I will close this bug. It can be opened again if escalated.

EVALUATION The socket adpator methods in jdk6 and earilier were not protected against close. This code has been replaced in jdk7 so these kinds of problems cannot happen. At this time we don't have plans to back-port these changes to jdk6.