diff options
author | Xianyuan Jia <xianyuanjia@google.com> | 2023-08-01 18:10:49 -0700 |
---|---|---|
committer | Xianyuan Jia <xianyuanjia@google.com> | 2023-08-01 18:10:49 -0700 |
commit | e4101d0633263d23a534fcc2ee175c24062054f3 (patch) | |
tree | 4b81e693f40a5e1aa0b868559ca4ab69697561e1 | |
parent | 336c57be777d6a74733e6a55e1f96d4c0781ce5e (diff) | |
download | mobly-snippet-lib-e4101d0633263d23a534fcc2ee175c24062054f3.tar.gz |
Check for null pointer in SimpleServer#getPrivateInetAddress
-rw-r--r-- | third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java index db7255a..40c32e7 100644 --- a/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java +++ b/third_party/sl4a/src/main/java/com/google/android/mobly/snippet/rpc/SimpleServer.java @@ -138,17 +138,19 @@ public abstract class SimpleServer { InetAddress candidate = null; Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); - for (NetworkInterface netint : Collections.list(nets)) { - if (!netint.isLoopback() || !netint.isUp()) { // Ignore if localhost or not active - continue; - } - Enumeration<InetAddress> addresses = netint.getInetAddresses(); - for (InetAddress address : Collections.list(addresses)) { - if (address instanceof Inet4Address) { - Log.d("local address " + address); - return address; // Prefer ipv4 + if (nets != null) { + for (NetworkInterface netint : Collections.list(nets)) { + if (!netint.isLoopback() || !netint.isUp()) { // Ignore if localhost or not active + continue; + } + Enumeration<InetAddress> addresses = netint.getInetAddresses(); + for (InetAddress address : Collections.list(addresses)) { + if (address instanceof Inet4Address) { + Log.d("local address " + address); + return address; // Prefer ipv4 + } + candidate = address; // Probably an ipv6 } - candidate = address; // Probably an ipv6 } } if (candidate != null) { |