Search code examples
javanetworkinglocalhostinetaddress

Java: InetAddress.getLocalHost(); throws java.net.UnknownHostException


Im having a problem running my Java application: When the following line gets executed, it thows an exception:

InetAddress.getLocalHost();

The following exception gets thrown:

java.net.UnknownHostException: ????????: ????????
at java.net.InetAddress.getLocalHost(InetAddress.java:1506)
at main.Main.main(Main.java:23)
Caused by: java.net.UnknownHostException: ????????
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)
at java.net.InetAddress.getLocalHost(InetAddress.java:1501)
... 1 more

I know that this is a problem with my local machine since it works on my virtual machines and other devices. I'm using Windows 10 and my hosts file is the default (non edited). What do the question marks mean? What could I try to fix this?


Solution

  • I figured out what the problem was: My hostname consisted of cyrillic letters. A user on Discord explained it to me like that:

    this seems to be a limitated at the C function getaddrinfofunction [12:14] which does make sense, considering cyrillic isn't a valid DNS name, so it's following RFC. [12:14] (even though hostname != dns name techically, but nuances). [12:15] RFC 952 and RFC 1123 have details info on it