I have problems with the latest mongodb driver 4.4.0 on my Linux machine with Java 17. It throws following exception:
Exception java.io.UncheckedIOException: java.net.SocketException: Unsupported address type
at DatagramSocketAdaptor.connect (DatagramSocketAdaptor.java:120)
at DatagramSocket.connect (DatagramSocket.java:474)
at DnsClient.doUdpQuery (DnsClient.java:408)
at DnsClient.query (DnsClient.java:214)
at Resolver.query (Resolver.java:81)
at DnsContext.c_getAttributes (DnsContext.java:434)
at ComponentDirContext.p_getAttributes (ComponentDirContext.java:235)
at PartialCompositeDirContext.getAttributes (PartialCompositeDirContext.java:141)
at PartialCompositeDirContext.getAttributes (PartialCompositeDirContext.java:129)
at InitialDirContext.getAttributes (InitialDirContext.java:171)
at DefaultDnsResolver.resolveAdditionalQueryParametersFromTxtRecords (DefaultDnsResolver.java:114)
at ConnectionString.<init> (ConnectionString.java:388)
at (#5:1)
Caused by: java.net.SocketException: Unsupported address type
at Net.translateToSocketException (Net.java:187)
at DatagramSocketAdaptor.connectInternal (DatagramSocketAdaptor.java:95)
at DatagramSocketAdaptor.connect (DatagramSocketAdaptor.java:118)
...
Caused by: java.nio.channels.UnsupportedAddressTypeException
at Net.checkAddress (Net.java:161)
at DatagramChannelImpl.connect (DatagramChannelImpl.java:1217)
at DatagramSocketAdaptor.connectInternal (DatagramSocketAdaptor.java:91)
...
It works as expected on my Windows with Java 17 and also on that Linux with Java 11.
How do I test it:
$ jshell --class-path mongodb-driver-core-4.4.0.jar
jshell> import com.mongodb.ConnectionString;
jshell> ConnectionString cs = new ConnectionString("mongodb+srv://xyz.mongodb.net/");
Expected result is javax.naming.NameNotFoundException: DNS name not found, however actual result is the java.nio.channels.UnsupportedAddressTypeException.
Any idea how to make it work?
After a lot of "jdbing" I found out, that I can make it work with older implementation of DatagramSocketImpl as is stated here https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/net/DatagramSocketImpl.html
I.e. if I set jdk.net.usePlainDatagramSocketImpl system property to "true" then it works.
Although I don't know proper solution or the real cause of the problem, I can live with the workaround and it works for me.