Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90d766b

Browse files
committed
Added null check
1 parent 4ab2003 commit 90d766b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

library/src/main/java/com/stealthcopter/networktools/ping/PingNative.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ private PingNative() {
1818

1919
public static PingResult ping(InetAddress host, int timeOutMillis) throws IOException, InterruptedException {
2020
PingResult pingResult = new PingResult(host);
21+
22+
if (host == null) {
23+
pingResult.isReachable = false;
24+
return pingResult;
25+
}
26+
2127
StringBuilder echo = new StringBuilder();
2228
Runtime runtime = Runtime.getRuntime();
2329

library/src/main/java/com/stealthcopter/networktools/ping/PingTools.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public static PingResult doNativePing(InetAddress ia, int timeOutMillis) throws
6363
*/
6464
public static PingResult doJavaPing(InetAddress ia, int timeOutMillis) {
6565
PingResult pingResult = new PingResult(ia);
66+
67+
if (ia == null) {
68+
pingResult.isReachable = false;
69+
return pingResult;
70+
}
71+
6672
try {
6773
long startTime = System.nanoTime();
6874
final boolean reached = ia.isReachable(timeOutMillis);

0 commit comments

Comments
 (0)