⚡ Sangsakala Proxy 🏠 Home
Skip to content

NullPointerException in HostsFileParser.getAddressForHost - hostsCache not initialized #400

Closed as not planned

Description

@msimonides-proton

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 ...

Activity

  1. ibauersachs commented on Feb 28, 2026

    @ibauersachs
    Member

    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?

  2. msimonides-proton commented on Mar 2, 2026

    @msimonides-proton
    Author

    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.

  3. msimonides-proton commented on Mar 2, 2026

    @msimonides-proton
    Author

    The environment is Android, several different versions (I can't believe I haven't included it in the original report :) )

  4. ibauersachs commented on Mar 8, 2026

    @ibauersachs
    Member

    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.

  5. added this to the v3.6.5 milestone on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    missing-feedbackQuestion not answered or clarifying information missing

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions