Rather than relying on undocumented kernel specific behavior, DatagramSocket::connect and DatagramSocket::send could explicitly use localhost when the specified peer address is the wildcard (and same for DatagramChannel and its socket adaptor).
This would allow to do things like:
var listener = new DatagramSocket(0);
var sender = new DatagramSocket(0);
var packet = new DatagramPacket(buf, buf.length);
sender.connect(listener.getLocalSocketAddress());
sender.send(packet);
which currently only works on mac when -Djava.net.preferIPv4Stack is specified.