java.net.BindException doesn't include host info even when jdk.includeInExceptions is set to hostInfo

Jaikiran Pai jai.forums2013 at gmail.com
Thu Jun 11 13:59:48 UTC 2020


Hello Alan,

On 11/06/20 7:18 pm, Alan Bateman wrote:
> On 11/06/2020 14:31, Jaikiran Pai wrote:
>> The security.properties file in Java 11 (and later) have a new
>> configuration:
>>
>> # The categories are:
>> #
>> #  hostInfo - IOExceptions thrown by java.net.Socket and the socket
>> types in the
>> #             java.nio.channels package will contain enhanced exception
>> #             message information
>> #
>> # The property setting in this file can be overridden by a system
>> property of
>> # the same name, with the same syntax and possible values.
>> #
>> #jdk.includeInExceptions=hostInfo
>>
>> As noted for that property, if hostInfo is set as a value for this
>> jdk.includeInExceptions then IOException thrown by java.net.Socket will
>> container additional information. Is this expected to work for all kinds
>> of connection issues related to Socket types? For example, I have a Java
>> program which creates a ServerSocket and (intentionally) binds it to
>> port which is already in use. I (as expected) keep seeing this
>> exception:
>>
> It's only used when when when connecting a stream-oriented socket
> fails. It could be extended of course although I would expect most
> servers have some form of log so the information on the local
> address/port might be there already.!
>
Having the host and port propagated as part of the exception message
right from the JDK (instead of the server code), I think, will help in
cases like the one reported here[1], where a ServerSocket is being
created with a port of 0. In this case, the library which is creating
that ServerSocket, itself won't know what port gets allocated.

Is this a valid use case to have this part of the JDK code enhanced to
include the additional host/port information (of course when that
security property is enabled)?

[1] https://github.com/quarkusio/quarkus/issues/9889

-Jaikiran




More information about the net-dev mailing list