Skip to content
Permalink
Browse files

implementation spotbugs Nulls, logging

  • Loading branch information...
silverailscolo committed Jun 19, 2019
1 parent 9439d44 commit 78d394133f226ea08a15669f8a176561fc4bf3fd
@@ -23,7 +23,7 @@
* @author Matthew Harris Copyright (C) 2011
* @since 2.11.4
*/
public abstract class AbstractIdTag extends AbstractNamedBean implements IdTag,Reportable {
public abstract class AbstractIdTag extends AbstractNamedBean implements IdTag, Reportable {

protected Reporter whereLastSeen = null;

@@ -73,9 +73,9 @@ public String toReportString() {
sb.append(userName);
}

// check to see if any properties have been added.
// check to see if any properties have been added
Set keySet = getPropertyKeys();
if(keySet!=null){
if (keySet != null) {
// we have properties, so append the values to the
// end of the report seperated by spaces.
for( Object s : keySet) {
@@ -732,33 +732,35 @@ public Sensor getSecondSensor() {

@Override
public void setInitialKnownStateFromFeedback() {
Sensor firstSensor = getFirstSensor();
if (_activeFeedbackType == ONESENSOR) {
// ONESENSOR feedback
if (getFirstSensor() != null) {
if (firstSensor != null) {
// set according to state of sensor
int sState = getFirstSensor().getKnownState();
int sState = firstSensor.getKnownState();
if (sState == Sensor.ACTIVE) {
newKnownState(THROWN);
} else if (sState == Sensor.INACTIVE) {
newKnownState(CLOSED);
}
} else {
log.warn("expected Sensor 1 not defined - " + getSystemName());
log.warn("expected Sensor 1 not defined - {}", getSystemName());
newKnownState(UNKNOWN);
}
} else if (_activeFeedbackType == TWOSENSOR) {
// TWOSENSOR feedback
int s1State = Sensor.UNKNOWN;
int s2State = Sensor.UNKNOWN;
if (getFirstSensor() != null) {
s1State = getFirstSensor().getKnownState();
if (firstSensor != null) {
s1State = firstSensor.getKnownState();
} else {
log.warn("expected Sensor 1 not defined - " + getSystemName());
log.warn("expected Sensor 1 not defined - {}", getSystemName());
}
if (getSecondSensor() != null) {
s2State = getSecondSensor().getKnownState();
Sensor secondSensor = getSecondSensor();
if (secondSensor != null) {
s2State = secondSensor.getKnownState();
} else {
log.warn("expected Sensor 2 not defined - " + getSystemName());
log.warn("expected Sensor 2 not defined - {}", getSystemName());
}
// set Turnout state according to sensors
if ((s1State == Sensor.ACTIVE) && (s2State == Sensor.INACTIVE)) {
@@ -804,9 +806,10 @@ protected void sensorPropertyChange(PropertyChangeEvent evt) {
newKnownState(CLOSED);
}
} else {
// unexected mismatch
log.warn("expected sensor " + getFirstNamedSensor().getName()
+ " was " + ((Sensor) evt.getSource()).getSystemName());
// unexpected mismatch
if ((log.isDebugEnabled()) && (getFirstNamedSensor() != null)) {
log.warn("expected sensor {} was {}", getFirstNamedSensor().getName(), ((Sensor) evt.getSource()).getSystemName());
}
}
// end ONESENSOR block
} else if (_activeFeedbackType == TWOSENSOR) {
@@ -83,9 +83,10 @@ public Element store(boolean storeState) {
Element e = new Element("idtag"); //NOI18N
// e.setAttribute("systemName", this.mSystemName); // not needed from 2.11.1
e.addContent(new Element("systemName").addContent(this.mSystemName)); //NOI18N
if (this.getUserName() != null && this.getUserName().length() > 0) {
String uName = this.getUserName();
if (uName != null && !uName.isEmpty()) {
// e.setAttribute("userName", this.getUserName()); // not needed from 2.11.1
e.addContent(new Element("userName").addContent(this.getUserName())); //NOI18N
e.addContent(new Element("userName").addContent(uName)); //NOI18N
}
if (this.getComment() != null && this.getComment().length() > 0) {
e.addContent(new Element("comment").addContent(this.getComment())); //NOI18N
@@ -53,11 +53,11 @@ void configureFromName(String systemName) {
// split out the basic information
String[] parts = systemName.split(":");
if (parts.length < 3) {
log.error("SignalMast system name needs at least three parts: " + systemName);
log.error("SignalMast system name needs at least three parts: {}", systemName);
throw new IllegalArgumentException("System name needs at least three parts: " + systemName);
}
if (!parts[0].equals("IF$shsm")) {
log.warn("SignalMast system name should start with IF$shsm but is " + systemName);
log.warn("SignalMast system name should start with IF$shsm but is {}", systemName);
}
String prefix = parts[0];
String system = parts[1];
@@ -94,14 +94,13 @@ void configureHeads(String parts[], int start) {
for (int i = start; i < parts.length; i++) {
String name = parts[i];
// check head exists
if (InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name) == null) {
SignalHead head = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
if (head == null) {
log.warn("Attempting to create Mast from non-existant signal head {}", name);
continue;
}
NamedBeanHandle<SignalHead> s
= InstanceManager.getDefault(NamedBeanHandleManager.class)
.getNamedBeanHandle(name,
InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name));
= InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(name, head);
heads.add(s);
}
}
@@ -111,16 +110,16 @@ public void setAspect(String aspect) {
// check it's a choice
if (!map.checkAspect(aspect)) {
// not a valid aspect
log.warn("attempting to set invalid aspect: " + aspect + " on mast: " + getDisplayName());
log.warn("attempting to set invalid aspect: {} on mast: {}", aspect, getDisplayName());
throw new IllegalArgumentException("attempting to set invalid aspect: " + aspect + " on mast: " + getDisplayName());
} else if (disabledAspects.contains(aspect)) {
log.warn("attempting to set an aspect that has been disabled: " + aspect + " on mast: " + getDisplayName());
log.warn("attempting to set an aspect that has been disabled: {} on mast: {}", aspect, getDisplayName());
throw new IllegalArgumentException("attempting to set an aspect that has been disabled: " + aspect + " on mast: " + getDisplayName());
}

// set the outputs
if (log.isDebugEnabled()) {
log.debug("setAspect \"" + aspect + "\", numHeads= " + heads.size());
log.debug("setAspect \"{}\", numHeads= {}", aspect, heads.size());
}
setAppearances(aspect);
// do standard processing
@@ -134,7 +133,7 @@ public void setHeld(boolean state) {
try {
h.getBean().setHeld(state);
} catch (java.lang.NullPointerException ex) {
log.error("NPE caused when trying to set Held due to missing signal head in mast " + getDisplayName());
log.error("NPE caused when trying to set Held due to missing signal head in mast {}", getDisplayName());
}
}
super.setHeld(state);
@@ -147,7 +146,7 @@ public void setLit(boolean state) {
try {
h.getBean().setLit(state);
} catch (java.lang.NullPointerException ex) {
log.error("NPE caused when trying to set Lit due to missing signal head in mast " + getDisplayName());
log.error("NPE caused when trying to set Lit due to missing signal head in mast {}", getDisplayName());
}
}
super.setLit(state);
@@ -162,13 +161,13 @@ public void setLit(boolean state) {
//taken out of the defaultsignalappearancemap
public void setAppearances(String aspect) {
if (map == null) {
log.error("No appearance map defined, unable to set appearance " + getDisplayName());
log.error("No appearance map defined, unable to set appearance {}", getDisplayName());
return;
}
if (map.getSignalSystem() != null && map.getSignalSystem().checkAspect(aspect) && map.getAspectSettings(aspect) != null) {
log.warn("Attempt to set " + getSystemName() + " to undefined aspect: " + aspect);
log.warn("Attempt to set {} to undefined aspect: {}", getSystemName(), aspect);
} else if ((map.getAspectSettings(aspect) != null) && (heads.size() > map.getAspectSettings(aspect).length)) {
log.warn("setAppearance to \"" + aspect + "\" finds " + heads.size() + " heads but only " + map.getAspectSettings(aspect).length + " settings");
log.warn("setAppearance to \"{}\" finds {} heads but only {} settings", aspect, heads.size(), map.getAspectSettings(aspect).length);
}

int delay = 0;
@@ -203,8 +202,7 @@ public void setAppearances(String aspect) {
if (delay == 0) {
head.setAppearance(toSet);
if (log.isDebugEnabled()) {
log.debug("Setting " + head.getSystemName() + " to "
+ head.getAppearanceName(toSet));
log.debug("Setting {} to {}", head.getSystemName(), head.getAppearanceName(toSet));
}
} else {
delayedSet.put(head, toSet);
@@ -244,8 +242,8 @@ public void run() {
try {
thrHead.setAppearance(delaySet.get(thrHead));
if (log.isDebugEnabled()) {
log.debug("Setting " + thrHead.getSystemName() + " to "
+ thrHead.getAppearanceName(delaySet.get(thrHead)));
log.debug("Setting {} to {}", thrHead.getSystemName(),
thrHead.getAppearanceName(delaySet.get(thrHead)));
}
Thread.sleep(delay);
} catch (InterruptedException ex) {

0 comments on commit 78d3941

Please sign in to comment.
You can’t perform that action at this time.