From 94e01acb7bd013f698df96b081f9020dc6206906 Mon Sep 17 00:00:00 2001 From: Kyle Feuz Date: Tue, 10 Jun 2014 01:37:46 -0700 Subject: [PATCH 1/2] Fixes Issue #2576 NPE when calling ip() on disconnected clients. --- java/libraries/net/src/processing/net/Client.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/libraries/net/src/processing/net/Client.java b/java/libraries/net/src/processing/net/Client.java index de39b6e9f..1c9e2ea9b 100644 --- a/java/libraries/net/src/processing/net/Client.java +++ b/java/libraries/net/src/processing/net/Client.java @@ -77,6 +77,7 @@ public class Client implements Runnable { socket = new Socket(this.host, this.port); input = socket.getInputStream(); output = socket.getOutputStream(); + ip = socket.getInetAddress().getHostAddress(); thread = new Thread(this); thread.start(); @@ -123,6 +124,7 @@ public class Client implements Runnable { input = socket.getInputStream(); output = socket.getOutputStream(); + ip = socket.getInetAddress().getHostAddress(); thread = new Thread(this); thread.start(); @@ -274,7 +276,7 @@ public class Client implements Runnable { * @brief Returns the IP address of the machine as a String */ public String ip() { - return socket.getInetAddress().getHostAddress(); + return ip; } From 3f01414d018d7bcae35b8f441d1f277d7783ddd5 Mon Sep 17 00:00:00 2001 From: Kyle Feuz Date: Sat, 1 Nov 2014 23:08:58 -0600 Subject: [PATCH 2/2] Changed ip() to return null when client has disconnected --- java/libraries/net/src/processing/net/Client.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/java/libraries/net/src/processing/net/Client.java b/java/libraries/net/src/processing/net/Client.java index 1c9e2ea9b..fb8fa95ee 100644 --- a/java/libraries/net/src/processing/net/Client.java +++ b/java/libraries/net/src/processing/net/Client.java @@ -51,7 +51,6 @@ public class Client implements Runnable { Thread thread; Socket socket; - String ip; int port; String host; @@ -77,7 +76,6 @@ public class Client implements Runnable { socket = new Socket(this.host, this.port); input = socket.getInputStream(); output = socket.getOutputStream(); - ip = socket.getInetAddress().getHostAddress(); thread = new Thread(this); thread.start(); @@ -124,7 +122,6 @@ public class Client implements Runnable { input = socket.getInputStream(); output = socket.getOutputStream(); - ip = socket.getInetAddress().getHostAddress(); thread = new Thread(this); thread.start(); @@ -276,7 +273,10 @@ public class Client implements Runnable { * @brief Returns the IP address of the machine as a String */ public String ip() { - return ip; + if (socket != null){ + return socket.getInetAddress().getHostAddress(); + } + return null; }