You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NullPointerException in HostsFileParser.getAddressForHost - hostsCache not initialized #400
We've started seeing this exception in our product in the wild after updating from 3.6.2 to 3.6.4 . It looks like validateCache doesn't always initialize the hostsCache.
Could have been this commit 5609998 ?
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference
at org.xbill.DNS.hosts.HostsFileParser.getAddressForHost(HostsFileParser.java:111)
at org.xbill.DNS.Lookup.lookupFromHostsFile(Lookup.java:649)
at org.xbill.DNS.Lookup.lookup(Lookup.java:586)
at org.xbill.DNS.Lookup.resolve(Lookup.java:675)
at org.xbill.DNS.Lookup.run(Lookup.java:697)
at ...
The commit probably introduced this, yes. But I have a hard time seeing how this is possible. The only way I see would be if java.nio.file.Files#getLastModifiedTime returns Instant.MIN.
Can you please give some more details about the environment you encounter this in?
We're seeing the issue in crash reports from a variety of devices and Android versions and it's quite common. We had to revert to an older version of the library. OTOH I haven't experienced the crash in day-to-day testing.
Do you even want to consider /etc/hosts in the lookup you're performing there? If not, you can disable it with Lookup.setDefaultHostsFileParser(null). Otherwise, please try the latest snapshot builds after commit c2d3b1b and see if that fixes the issue.
If I may, I would strongly suggest you switch to async lookups via LookupSession, especially since you're calling from already async code.
Activity
ibauersachs commentedon Feb 28, 2026
The commit probably introduced this, yes. But I have a hard time seeing how this is possible. The only way I see would be if
java.nio.file.Files#getLastModifiedTimereturnsInstant.MIN.Can you please give some more details about the environment you encounter this in?
Handle invalid/uninitialized file times
Windows' Selector impl doesn't like to be spied upon
msimonides-proton commentedon Mar 2, 2026
If it helps, here's how we're using DNSJava: https://github.com/ProtonVPN/android-app/blob/c99f8fada63bfbc9225c24a4e19cecbc7b8cfb54/app/src/main/java/com/protonvpn/android/vpn/VpnDns.kt#L128
We're seeing the issue in crash reports from a variety of devices and Android versions and it's quite common. We had to revert to an older version of the library. OTOH I haven't experienced the crash in day-to-day testing.
msimonides-proton commentedon Mar 2, 2026
The environment is Android, several different versions (I can't believe I haven't included it in the original report :) )
ibauersachs commentedon Mar 8, 2026
Do you even want to consider /etc/hosts in the lookup you're performing there? If not, you can disable it with
Lookup.setDefaultHostsFileParser(null). Otherwise, please try the latest snapshot builds after commit c2d3b1b and see if that fixes the issue.If I may, I would strongly suggest you switch to async lookups via
LookupSession, especially since you're calling from already async code.