From 42f973ebe0e59cbe75008e9edf8c667b0b1ab080 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 15 Sep 2015 22:03:11 -0700 Subject: [PATCH] Java: Don't raise illegal state exceptions unless really necessary. - Ignore no-op calls to setServerMode() / setClientMode(). - Duplicate calls to initialize() act as a restart. - shutdown() silently does nothing if not running. --- .../first/wpilibj/networktables/NetworkTable.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java b/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java index f65628d84b..9d7ece0ba4 100644 --- a/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java +++ b/java/src/edu/wpi/first/wpilibj/networktables/NetworkTable.java @@ -36,7 +36,8 @@ public class NetworkTable implements ITable, IRemote { * initializes network tables */ public synchronized static void initialize() { - checkInit(); + if (running) + shutdown(); if (client) NetworkTablesJNI.startClient(ipAddress, port); else @@ -49,8 +50,7 @@ public class NetworkTable implements ITable, IRemote { */ public synchronized static void shutdown() { if (!running) - throw new IllegalStateException( - "Network tables has not yet been initialized"); + return; if (client) NetworkTablesJNI.stopClient(); else @@ -63,6 +63,8 @@ public class NetworkTable implements ITable, IRemote { * This must be called before initalize or getTable */ public synchronized static void setServerMode() { + if (!client) + return; checkInit(); client = false; } @@ -72,6 +74,8 @@ public class NetworkTable implements ITable, IRemote { * This must be called before initalize or getTable */ public synchronized static void setClientMode() { + if (client) + return; checkInit(); client = true; } @@ -91,6 +95,8 @@ public class NetworkTable implements ITable, IRemote { * mode */ public synchronized static void setIPAddress(final String address) { + if (ipAddress == address) + return; checkInit(); ipAddress = address; } @@ -100,6 +106,8 @@ public class NetworkTable implements ITable, IRemote { * mode or listen to in server mode */ public synchronized static void setPort(int aport) { + if (port == aport) + return; checkInit(); port = aport; }