Catch NPE thrown by NetworkInterface.getNetworkInterfaces().

This commit is contained in:
akwizgran
2022-03-05 13:54:48 +00:00
parent f5f7b3eb51
commit 79051439c5
2 changed files with 7 additions and 11 deletions

View File

@@ -26,7 +26,7 @@ public class NetworkUtils {
// Despite what the docs say, the return value can be null // Despite what the docs say, the return value can be null
//noinspection ConstantConditions //noinspection ConstantConditions
return ifaces == null ? emptyList() : list(ifaces); return ifaces == null ? emptyList() : list(ifaces);
} catch (SocketException e) { } catch (SocketException | NullPointerException e) {
logException(LOG, WARNING, e); logException(LOG, WARNING, e);
return emptyList(); return emptyList();
} }

View File

@@ -7,14 +7,13 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
import static java.net.NetworkInterface.getNetworkInterfaces;
import static java.util.Collections.list; import static java.util.Collections.list;
import static org.briarproject.bramble.util.NetworkUtils.getNetworkInterfaces;
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
@@ -25,14 +24,11 @@ abstract class AbstractSecureRandomProvider implements SecureRandomProvider {
out.writeLong(System.currentTimeMillis()); out.writeLong(System.currentTimeMillis());
out.writeLong(System.nanoTime()); out.writeLong(System.nanoTime());
out.writeLong(Runtime.getRuntime().freeMemory()); out.writeLong(Runtime.getRuntime().freeMemory());
Enumeration<NetworkInterface> ifaces = getNetworkInterfaces(); for (NetworkInterface i : getNetworkInterfaces()) {
if (ifaces != null) { for (InetAddress a : list(i.getInetAddresses()))
for (NetworkInterface i : list(ifaces)) { out.write(a.getAddress());
for (InetAddress a : list(i.getInetAddresses())) byte[] hardware = i.getHardwareAddress();
out.write(a.getAddress()); if (hardware != null) out.write(hardware);
byte[] hardware = i.getHardwareAddress();
if (hardware != null) out.write(hardware);
}
} }
for (Entry<String, String> e : System.getenv().entrySet()) { for (Entry<String, String> e : System.getenv().entrySet()) {
out.writeUTF(e.getKey()); out.writeUTF(e.getKey());