JDK-8234083 : DatagramSocket should report SO_BROADCAST as a supported option
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 9,13
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2019-11-13
  • Updated: 2023-07-20
  • Resolved: 2019-11-21
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 14
14 b25Fixed
Related Reports
Blocks :  
Relates :  
Description
DatagramSocket has setBroadcast/getBroadcast methods, but curriously omits to report SO_BROADCAST as a supported option.
Comments
Note: the source code changes for this fix were accidentally pushed with JDK-8234103. The changeset pushed with JDK-8234083 thus only has the test changes. For the record the source changes that should have gone here are: --- old/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java 2019-11-14 15:32:07.000000000 +0000 +++ new/src/java.base/share/classes/java/net/AbstractPlainDatagramSocketImpl.java 2019-11-14 15:32:07.000000000 +0000 @@ -406,6 +406,7 @@ options.add(StandardSocketOptions.SO_SNDBUF); options.add(StandardSocketOptions.SO_RCVBUF); options.add(StandardSocketOptions.SO_REUSEADDR); + options.add(StandardSocketOptions.SO_BROADCAST); options.add(StandardSocketOptions.IP_TOS); if (isReusePortAvailable()) options.add(StandardSocketOptions.SO_REUSEPORT); @@ -418,6 +419,7 @@ options.add(StandardSocketOptions.SO_SNDBUF); options.add(StandardSocketOptions.SO_RCVBUF); options.add(StandardSocketOptions.SO_REUSEADDR); + options.add(StandardSocketOptions.SO_BROADCAST); options.add(StandardSocketOptions.IP_TOS); options.add(StandardSocketOptions.IP_MULTICAST_IF); options.add(StandardSocketOptions.IP_MULTICAST_TTL); @@ -460,6 +462,8 @@ setOption(SocketOptions.SO_REUSEADDR, value); } else if (name == StandardSocketOptions.SO_REUSEPORT) { setOption(SocketOptions.SO_REUSEPORT, value); + } else if (name == StandardSocketOptions.SO_BROADCAST) { + setOption(SocketOptions.SO_BROADCAST, value); } else if (name == StandardSocketOptions.IP_TOS) { int i = ((Integer)value).intValue(); if (i < 0 || i > 255) @@ -499,6 +503,8 @@ return (T) getOption(SocketOptions.SO_REUSEADDR); } else if (name == StandardSocketOptions.SO_REUSEPORT) { return (T) getOption(SocketOptions.SO_REUSEPORT); + } else if (name == StandardSocketOptions.SO_BROADCAST) { + return (T) getOption(SocketOptions.SO_BROADCAST); } else if (name == StandardSocketOptions.IP_TOS) { return (T) getOption(SocketOptions.IP_TOS); } else if (name == StandardSocketOptions.IP_MULTICAST_IF) { ( see http://cr.openjdk.java.net/~pconcannon/8234083/webrevs/webrev.00/open.patch )
22-11-2019

URL: https://hg.openjdk.java.net/jdk/jdk/rev/61091a42f19d User: dfuchs Date: 2019-11-21 16:39:56 +0000
21-11-2019

DatagramSocket doesn't specify the socket options that it supports with the setOption/getOption methods. DatagramChannel has a table in its class description. So I'll bet the methods aren't used much with DatagramSocket/MulticastSocket and no-one noticed that SO_BROADCAST wasn't supported.
17-11-2019