Help Track Down a Flatpak Bug!

Mar 16, 2023
D

I’ve discovered something weird, but I can’t figure it out on my own.

The following Java code works outside of Flatpak, and works inside Flatpak for most distros - But in Flatpak on Arch Linux, it throws an exception:

import java.net.InetAddress;

public final class Main {
  public static void main(String[] args) {
    try {
      InetAddress.getLocalHost();
      System.out.println("Completed without issue!");
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
}

Output outside Flatpak or on most distros:

Completed without issue!

Output in Flatpak on Arch Linux:

java.net.UnknownHostException: archlinux: archlinux: Name or service not known
        at java.base/java.net.InetAddress.getLocalHost(InetAddress.java:1661)
        at Main.main(Main.java:6)
Caused by: java.net.UnknownHostException: archlinux: Name or service not known
        at java.base/java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.base/java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:929)
        at java.base/java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1534)
        at java.base/java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:848)
        at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1524)
        at java.base/java.net.InetAddress.getLocalHost(InetAddress.java:1656)
        ... 1 more

I’ve created a repo with a reproducible example + simple build steps in the README: GitHub - dginovker/FlatpakJavaBug: Example bug in Flatpak Java


  • Granting Flatpak with all the permissions via Flatseal doesn’t resolve the issue
  • Issue happens with OpenJDK 11 and OpenJDK17 (although I suspect this isn’t actually a Java issue)

Anyone have other suggestions on how to narrow this down?

D

Seems to work on Asahi Linux with the following /etc/hosts:

# Host addresses
127.0.0.1  localhost
127.0.1.1  asahi-mac
::1        localhost ip6-localhost ip6-loopback
ff02::1    ip6-allnodes
ff02::2    ip6-allrouters

Edit: Matching this hosts file on the computer with issues doesn’t seem to resolve the issue

F

On my computer with Arch Linux:
FlatpakJavaBug]$ flatpak run io.github.flatpakjavabug
Completed without issue!

H

does it have --share=network ?

But the app is buggy. It shouldn’t crash on that kind of conditions?

D
Replying to #4

Yup, it has --share=network

It shouldn’t crash

For clarity it’s not crashing, the code is entering the catch branch above and calling System.exit(1), but the problem is it doesn’t do this outside Flatpak

D
Replying to #3

On my computer with Arch Linux:
FlatpakJavaBug]$ flatpak run io.github.flatpakjavabug
Completed without issue!

Thanks for checking :heart: . This part is nuts, it’s working haphazadly for different people. Can you post your /etc/hosts? I don’t actually think it is the /etc/hosts causing the issue, but I don’t know enough about Linux to have any other leads

F
Replying to #6
cat /etc/hosts
# Static table lookup for hostnames.
# See hosts(5) for details.
127.0.0.1	localhost
127.0.1.1	bueroal2
D

Someone said this on Discord, but I’m not sure what the before/after of the hosts file was:

I just tested an install of arch Linux and had the same issue initially but fixed by modifying the hosts file & rebooting

D
Replying to #8

Figured i’d post here instead of Discord

Original, Broken Hosts

D
Replying to #9

“New Users Can Only Put One Photo Per Post”

Modified, Working Hosts