From c9836f8006c14d0851591319e41155238be23b66 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 21 Aug 2021 18:10:02 +0200 Subject: [PATCH] Prevent crash --- .../java/eu/faircode/email/EmailService.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index 944fc5104e..e0ddaa3ce7 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -503,19 +503,28 @@ public class EmailService implements AutoCloseable { boolean has4 = false; boolean has6 = false; - Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); - while (interfaces != null && interfaces.hasMoreElements()) { - NetworkInterface ni = interfaces.nextElement(); - for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) { - InetAddress addr = iaddr.getAddress(); - boolean local = (addr.isLoopbackAddress() || addr.isLinkLocalAddress()); - EntityLog.log(context, "Interface=" + ni + " addr=" + addr + " local=" + local); - if (!local) - if (addr instanceof Inet4Address) - has4 = true; - else if (addr instanceof Inet6Address) - has6 = true; + try { + Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); + while (interfaces != null && interfaces.hasMoreElements()) { + NetworkInterface ni = interfaces.nextElement(); + for (InterfaceAddress iaddr : ni.getInterfaceAddresses()) { + InetAddress addr = iaddr.getAddress(); + boolean local = (addr.isLoopbackAddress() || addr.isLinkLocalAddress()); + EntityLog.log(context, "Interface=" + ni + " addr=" + addr + " local=" + local); + if (!local) + if (addr instanceof Inet4Address) + has4 = true; + else if (addr instanceof Inet6Address) + has6 = true; + } } + } catch (Throwable ex2) { + Log.e(ex2); + /* + java.lang.NullPointerException: Attempt to read from field 'java.util.List java.net.NetworkInterface.childs' on a null object reference + at java.net.NetworkInterface.getAll(NetworkInterface.java:498) + at java.net.NetworkInterface.getNetworkInterfaces(NetworkInterface.java:398) + */ } EntityLog.log(context, "Address main=" + main +