JDK-8235330 : Deprecate MulticastSocket methods that operate on java.net.InetAddress
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.net
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 14
  • Submitted: 2019-12-04
  • Updated: 2019-12-09
  • Resolved: 2019-12-07
Related Reports
CSR :  
Description
Summary
-------

Deprecate, **not** for removal, the following methods in `java.net.MulticastSocket`:

     1. MulticastSocket.getInterface()
     2. MulticastSocket.setInterface(InetAddress inf)
     3. MulticastSocket.joinGroup(InetAddress mcastaddr)
     4. MulticastSocket.leaveGroup(InetAddress mcastaddr)
     5. MulticastSocket.getLoopbackMode()
     6. MulticastSocket.setLoopbackMode(boolean disable)

Problem
-------

Methods 1 - 4 operate on `java.net.InetAddress` instead of `java.net.NetworkInterface` and thus do not allow to pass or return the `NetworkInterface` set for a `MulticastSocket`. It is preferred to use `NetworkInterface` as an `InetAddress` may not uniquely identify a `NetworkInterface`.

Methods 5 - 6 operate on `SocketOptions.IP_MULTICAST_LOOP`. However, `MulticastSocket.setOption` conforms with `StandardSocketOptions.IP_MULTICAST_LOOP`, which should be used instead.

Solution
--------

Add the `@Deprecated` annotation and the `@deprecated` javadoc tag to the methods in question.

Specification
-------------

Webrev: http://cr.openjdk.java.net/~jboes/webrevs/8233319/webrev.01/

Specdiff attached.


Comments
Thanks for noting, fixed - it has to be a @link tag instead of @code.
09-12-2019

In getLoopbackMode, there seems to be a typo in the javadoc "Use #getOption(SocketOption) with StandardSocketOptions.IP_MULTICAST_LOOP instead" where getOption isn't rendering as a link. Please check this before pushing. Moving to Approved.
07-12-2019

I think we can improve the wording "This method does not accept the network interface on which ..." but otherwise this looks good. The methods that take an InetAddress to identity the network or multicast group are obsolete and have had replacements since Java SE 1.4. The setLoopbackMode/getLoopbackMode was a hazard due to a mistake in Java SE 1.4 that cannot be fixed for compatibility reasons - the setOption/getOption methods added in Java SE 9 are a better choice when the multicast loopback mode needs to be changed or queried.
04-12-2019