diff --git a/java/src/jmri/jmrit/blockboss/BlockBossLogic.java b/java/src/jmri/jmrit/blockboss/BlockBossLogic.java index 4a4226a48d7..0f92a519a8d 100644 --- a/java/src/jmri/jmrit/blockboss/BlockBossLogic.java +++ b/java/src/jmri/jmrit/blockboss/BlockBossLogic.java @@ -125,7 +125,7 @@ public class BlockBossLogic extends Siglet implements java.beans.VetoableChangeL static public final int TRAILINGDIVERGING = 3; static public final int FACING = 4; - int mode = 0; + private int mode = 0; /** * Create an object to drive a specific signal head. @@ -134,6 +134,7 @@ public class BlockBossLogic extends Siglet implements java.beans.VetoableChangeL */ public BlockBossLogic(@Nonnull String name) { super(name + Bundle.getMessage("_BlockBossLogic")); + java.util.Objects.requireNonNull(name, "BlockBossLogic name cannot be null"); this.name = name; log.trace("Create BBL {}", name); @@ -229,7 +230,7 @@ public void setSensor5(String name) { } /** - * Return the system name of the sensors 1-5 being monitored. + * Get the system name of the sensors 1-5 being monitored. * * @return system name; null if no sensor configured */ @@ -281,7 +282,7 @@ public void setTurnout(String name) { } /** - * Return the system name of the turnout being monitored. + * Get the system name of the turnout being monitored. * * @return system name; null if no turnout configured */ @@ -326,7 +327,7 @@ public void setWatchedSignal1(String name, boolean useFlash) { } /** - * Return the system name of the signal head being monitored for first route. + * Get the system name of the signal head being monitored for first route. * * @return system name; null if no primary signal head is configured */ @@ -352,7 +353,7 @@ public void setWatchedSignal1Alt(String name) { } /** - * Return the system name of the alternate signal head being monitored for first + * Get the system name of the alternate signal head being monitored for first * route. * * @return system name; null if no signal head is configured @@ -379,7 +380,7 @@ public void setWatchedSignal2(String name) { } /** - * Return the system name of the signal head being monitored for the 2nd route. + * Get the system name of the signal head being monitored for the 2nd route. * * @return system name; null if no signal head is configured */ @@ -405,7 +406,7 @@ public void setWatchedSignal2Alt(String name) { } /** - * Return the system name of the secondary signal head being monitored for the + * Get the system name of the secondary signal head being monitored for the * 2nd route. * * @return system name; null if no secondary signal head is configured @@ -431,7 +432,7 @@ public void setWatchedSensor1(String name) { } /** - * Return the original name of the sensor1 being monitored. + * Get the original name of the sensor1 being monitored. * * @return original name; null if no sensor is configured */ @@ -456,7 +457,7 @@ public void setWatchedSensor1Alt(String name) { } /** - * Return the system name of the sensor1Alt being monitored. + * Get the system name of the sensor1Alt being monitored. * * @return system name; null if no sensor is configured */ @@ -481,7 +482,7 @@ public void setWatchedSensor2(String name) { } /** - * Return the system name of the sensor2 being monitored. + * Get the system name of the sensor2 being monitored. * * @return system name; null if no sensor is configured */ @@ -506,7 +507,7 @@ public void setWatchedSensor2Alt(String name) { } /** - * Return the system name of the sensor2Alt being monitored. + * Get the system name of the sensor2Alt being monitored. * * @return system name; null if no sensor is configured */ @@ -561,7 +562,7 @@ public boolean getDistantSignal() { return distantSignal; } - boolean mHold = false; + private boolean mHold = false; /** * Provide the current value of the "hold" parameter. @@ -589,7 +590,7 @@ public void setHold(boolean m) { setOutput(); // to invoke the new state } - String name; + private String name; @Nonnull NamedBeanHandle driveSignal; @@ -626,11 +627,10 @@ public void setApproachSensor1(String name) { if (approachSensor1.getBean() == null) { log.warn(Bundle.getMessage("BeanXNotFound", Bundle.getMessage("Approach_Sensor1_"), name)); } - } /** - * Return the system name of the sensor being monitored. + * Get the system name of the sensor being monitored. * * @return system name; null if no sensor configured */ @@ -1145,7 +1145,6 @@ void doApproach() { driveSignal.getBean().setLit(true); } } - return; } // Due to an older configuration & storage paradigm, this class @@ -1184,7 +1183,7 @@ public void retain() { } /** - * Return the BlockBossLogic item governing a specific signal head by its name, + * Get the BlockBossLogic item governing a specific signal head by its name, * having removed it from use. * * @param signal name of the signal head object @@ -1202,7 +1201,7 @@ public static BlockBossLogic getStoppedObject(String signal) { } /** - * Return the BlockBossLogic item governing a specific signal head, having + * Get the BlockBossLogic item governing a specific signal head, having * removed it from use. * * @param sh signal head object @@ -1231,7 +1230,7 @@ public static BlockBossLogic getStoppedObject(@Nonnull SignalHead sh) { } /** - * Return the BlockBossLogic item governing a specific signal head located from its name. + * Get the BlockBossLogic item governing a specific signal head located from its name. *

* Unlike {@link BlockBossLogic#getStoppedObject(String signal)} this does * not remove the object from being used. @@ -1250,7 +1249,7 @@ public static BlockBossLogic getExisting(@Nonnull String signal) { } /** - * Return the BlockBossLogic item governing a specific signal head object. + * Get the BlockBossLogic item governing a specific signal head object. *

* Unlike {@link BlockBossLogic#getStoppedObject(String signal)} this does * not remove the object from being used. diff --git a/java/src/jmri/jmrit/logix/PortalManager.java b/java/src/jmri/jmrit/logix/PortalManager.java index a66cd34d041..0258e2864b0 100644 --- a/java/src/jmri/jmrit/logix/PortalManager.java +++ b/java/src/jmri/jmrit/logix/PortalManager.java @@ -7,14 +7,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Hashtable; - +import javax.annotation.Nonnull; import javax.annotation.OverridingMethodsMustInvokeSuper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; - /** * Basic implementation of a PortalManager. *

@@ -73,9 +71,11 @@ public Collection getPortalSet() { /* * Create a new Portal with a given user name. * - * @return null if a Portal with the same userName already exists + * @return null if a Portal with the same userName already exists, + * or if an empty userName was requested */ public Portal createNewPortal(@Nonnull String userName) { + java.util.Objects.requireNonNull(userName, "Name cannot be null"); // Check that Portal does not already exist Portal portal; if (userName.trim().length() > 0) { diff --git a/java/test/jmri/jmrit/blockboss/BlockBossLogicTest.java b/java/test/jmri/jmrit/blockboss/BlockBossLogicTest.java index 11adaac0288..452fdb44a1d 100644 --- a/java/test/jmri/jmrit/blockboss/BlockBossLogicTest.java +++ b/java/test/jmri/jmrit/blockboss/BlockBossLogicTest.java @@ -179,8 +179,17 @@ public void testSimpleBlockNoNextLimited() throws jmri.JmriException { // check for basic not-fail if no signal name was set @Test public void testSimpleBlockNoSignal() throws jmri.JmriException { - try { + new BlockBossLogic(null); + } catch (java.lang.NullPointerException e) { + // this is expected + } + } + + // check for basic not-fail if empty signal name was set + @Test + public void testSimpleBlockEmptyName() throws jmri.JmriException { + try { new BlockBossLogic(""); } catch (java.lang.IllegalArgumentException e) { // this is expected diff --git a/java/test/jmri/jmrit/logix/PortalTest.java b/java/test/jmri/jmrit/logix/PortalTest.java index f68845f9fa1..c30a5f9344a 100644 --- a/java/test/jmri/jmrit/logix/PortalTest.java +++ b/java/test/jmri/jmrit/logix/PortalTest.java @@ -23,8 +23,10 @@ public class PortalTest { @Test public void testCtor() { - Portal p = _portalMgr.createNewPortal(""); // @Nonnull annotated userName - Assert.assertNull("No User Name", p); // Portals must have a user name + Portal p = _portalMgr.createNewPortal(null); + Assert.assertNull("Null User Name", p); // Portals must have a user name + p = _portalMgr.createNewPortal(""); + Assert.assertNull("Empty User Name", p); p = _portalMgr.createNewPortal("portal_1"); Assert.assertNotNull("Has User Name", p); }