Skip to content

Commit

Permalink
Merge pull request #5708 from bobjacobsen/more-spotbugs
Browse files Browse the repository at this point in the history
More spotbugs
  • Loading branch information
bobjacobsen committed Aug 27, 2018
2 parents 6cc135e + 054ff5e commit a05ecec
Show file tree
Hide file tree
Showing 24 changed files with 39 additions and 101 deletions.
9 changes: 3 additions & 6 deletions java/src/apps/Apps.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public Apps() {
configFilename = FileUtil.getProfilePath() + Profile.CONFIG_FILENAME;
System.setProperty("org.jmri.Apps.configFilename", Profile.CONFIG_FILENAME);
Profile profile = ProfileManager.getDefault().getActiveProfile();
log.info("Starting with profile {}", (profile != null ? profile.getId() : "<none>"));
log.info("Starting with profile {}", profile.getId());

// rapid language set; must follow up later with full setting as part of preferences
apps.gui.GuiLafPreferencesManager.setLocaleMinimally(profile);
Expand Down Expand Up @@ -848,11 +848,8 @@ protected JPanel statusPanel() {
pane2.add(new JLabel(line3()));

Profile profile = ProfileManager.getDefault().getActiveProfile();
if (profile != null) {
pane2.add(new JLabel(Bundle.getMessage("ActiveProfile", profile.getName())));
} else {
pane2.add(new JLabel(Bundle.getMessage("FailedProfile")));
}
pane2.add(new JLabel(Bundle.getMessage("ActiveProfile", profile.getName())));

// add listener for Com port updates
ConnectionStatus.instance().addPropertyChangeListener(this);
int i = 0;
Expand Down
2 changes: 1 addition & 1 deletion java/src/apps/AppsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected void configureProfile() {
// Apps.setConfigFilename() does not reset the system property
System.setProperty("org.jmri.Apps.configFilename", Profile.CONFIG_FILENAME);
Profile profile = ProfileManager.getDefault().getActiveProfile();
log.info("Starting with profile {}", profile != null ? profile.getId() : "<none>");
log.info("Starting with profile {}", profile.getId());
} else {
log.error("Specify profile to use as command line argument.");
log.error("If starting with saved profile configuration, ensure the autoStart property is set to \"true\"");
Expand Down
4 changes: 2 additions & 2 deletions java/src/apps/gui3/Apps3.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ protected void configureProfile() {
// Apps.setConfigFilename() does not reset the system property
System.setProperty("org.jmri.Apps.configFilename", Profile.CONFIG_FILENAME);
Profile profile = ProfileManager.getDefault().getActiveProfile();
log.info("Starting with profile {}", profile != null ? profile.getId() : "<none>");
log.info("Starting with profile {}", profile.getId());

// rapid language set; must follow up later with full setting as part of preferences
apps.gui.GuiLafPreferencesManager.setLocaleMinimally(profile);
Expand All @@ -380,7 +380,7 @@ protected void setAndLoadPreferenceFile() {
Profile profile = ProfileManager.getDefault().getActiveProfile();
if (!GraphicsEnvironment.isHeadless()) {
JOptionPane.showMessageDialog(sp,
Bundle.getMessage("SingleConfigMigratedToSharedConfig", profile != null ? profile.getName() : "<none>"),
Bundle.getMessage("SingleConfigMigratedToSharedConfig", profile.getName()),
jmri.Application.getApplicationName(),
JOptionPane.INFORMATION_MESSAGE);
}
Expand Down
17 changes: 7 additions & 10 deletions java/src/apps/gui3/FirstTimeStartUpWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,13 @@ public void run() {
}
}
Profile project = ProfileManager.getDefault().getActiveProfile();
if (project != null) {
InstanceManager.getDefault(RosterConfigManager.class).setDefaultOwner(owner.getText());
InstanceManager.getDefault(GuiLafPreferencesManager.class).setLocale(Locale.getDefault());
InstanceManager.getDefault(RosterConfigManager.class).savePreferences(project);
InstanceManager.getDefault(GuiLafPreferencesManager.class).savePreferences(project);
connectionConfigPane.savePreferences();
InstanceManager.getDefault(ConfigureManager.class).storePrefs();
} else {
log.error("Unable to save first time preferences due to missing profile.");
}
InstanceManager.getDefault(RosterConfigManager.class).setDefaultOwner(owner.getText());
InstanceManager.getDefault(GuiLafPreferencesManager.class).setLocale(Locale.getDefault());
InstanceManager.getDefault(RosterConfigManager.class).savePreferences(project);
InstanceManager.getDefault(GuiLafPreferencesManager.class).savePreferences(project);
connectionConfigPane.savePreferences();
InstanceManager.getDefault(ConfigureManager.class).storePrefs();

dispose();
}
}
Expand Down
4 changes: 0 additions & 4 deletions java/src/jmri/configurexml/BlockManagerXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ void addPath(Element e, Path p) {
}

void addBeanSetting(Element e, BeanSetting bs) {
if (bs.getBean() == null) {
log.error("Invalid BeanSetting - did not save");
return;
}
// persist bean name, type and value
Element bse = new Element("beansetting");
// for now, assume turnout
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/implementation/MatrixSignalMast.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void setOutput(@Nonnull String colname, @Nonnull String turnoutname) {
} else {
Turnout turn = jmri.InstanceManager.turnoutManagerInstance().getTurnout(turnoutname);
if (turn == null) {
log.error("setOutpout couldn't locate turnout {}", turn);
log.error("setOutpout couldn't locate turnout {}", turnoutname);
return;
}
NamedBeanHandle<Turnout> namedTurnout = jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(turnoutname, turn);
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/implementation/TurnoutSignalMast.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static class TurnoutAspect {
state = turnoutState;
Turnout turn = jmri.InstanceManager.turnoutManagerInstance().getTurnout(turnoutName);
if (turn == null) {
log.error("TurnoutAspect couldn't locate turnout {}", turn);
log.error("TurnoutAspect couldn't locate turnout {}", turnoutName);
return;
}
namedTurnout = jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(turnoutName, turn);
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/dispatcher/DispatcherFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -3162,7 +3162,7 @@ protected void addMouseListenerToHeader(JTable table) {
table.getTableHeader().addMouseListener(mouseHeaderListener);
}

protected class HeaderActionListener implements ActionListener {
static protected class HeaderActionListener implements ActionListener {

TableColumn tc;
XTableColumnModel tcm;
Expand Down
3 changes: 0 additions & 3 deletions java/src/jmri/jmrit/display/LocoIcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ public void init() {
@Override
public void doMouseReleased(MouseEvent event) {
List<Positionable> selections = _editor.getSelectedItems(event);
if (selections == null) {
return;
}
for (int i = 0; i < selections.size(); i++) {
if (selections.get(i) instanceof IndicatorTrack) {
IndicatorTrack t = (IndicatorTrack) selections.get(i);
Expand Down
4 changes: 1 addition & 3 deletions java/src/jmri/jmrit/display/layoutEditor/LayoutBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -3181,10 +3181,8 @@ public void propertyChange(PropertyChangeEvent e) {
LayoutBlock srcEvent = (LayoutBlock) e.getSource();

if (e.getPropertyName().equals("NewRoute")) {
LayoutBlock lbkblock = (LayoutBlock) e.getNewValue();

if (enableUpdateRouteLogging) {
log.info("==Event type {} New {}", e.getPropertyName(), lbkblock.getDisplayName());
log.info("==Event type {} New {}", e.getPropertyName(), ((LayoutBlock) e.getNewValue()).getDisplayName());
}
} else if (e.getPropertyName().equals("through-path-added")) {
if (enableUpdateRouteLogging) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ else if (lc.getConnectedType() >= LayoutTrack.SLIP_A
prevConnection = lt;
if ((lt != null) && (lt.getTurnout() != null)) {
int type = lc.getXoverBoundaryType();
bs = null;
// bs is known to be null at this point
if (lt.getTurnout() != null) {
if (type == LayoutConnectivity.XOVER_BOUNDARY_AB) {
bs = new BeanSetting(lt.getTurnout(), lt.getTurnoutName(), Turnout.CLOSED);
Expand Down
10 changes: 3 additions & 7 deletions java/src/jmri/jmrit/mailreport/ReportContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,9 @@ public String getReport(boolean reportNetworkInfo) {
addCommunicationPortInfo();

Profile profile = ProfileManager.getDefault().getActiveProfile();
if (profile != null) {
addString("Active profile: " + profile.getName() + " ");
addString("Profile location: " + profile.getPath().getPath() + " ");
addString("Profile ID: " + profile.getId() + " ");
} else {
addString("No profile present");
}
addString("Active profile: " + profile.getName() + " ");
addString("Profile location: " + profile.getPath().getPath() + " ");
addString("Profile ID: " + profile.getId() + " ");

addString("JMRI Node ID: "+ jmri.util.node.NodeIdentity.identity() );

Expand Down
10 changes: 5 additions & 5 deletions java/src/jmri/jmrit/signalling/SignallingPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ protected final void eventEditorMousePressed() {
* @return an appropriate combobox for this signal head
*/
@Override
protected JComboBox getEditorBox(int row) {
protected JComboBox<String> getEditorBox(int row) {
return getStateEditorBox(row);
}

Expand Down Expand Up @@ -1756,7 +1756,7 @@ public void setValueAt(Object type, int r, int c) {
* @return A combobox containing the valid aspect names for this mast
*/
@Override
JComboBox getStateEditorBox(int row) {
JComboBox<String> getStateEditorBox(int row) {
// create dummy comboBox, override in extended classes for each bean
JComboBox<String> editCombo = new JComboBox<>();
editCombo.addItem(SET_TO_UNOCCUPIED);
Expand Down Expand Up @@ -1845,7 +1845,7 @@ public void setValueAt(Object type, int r, int c) {
* @return A combobox containing the valid aspect names for this mast
*/
@Override
JComboBox getStateEditorBox(int row) {
JComboBox<String> getStateEditorBox(int row) {
// create dummy comboBox, override in extended classes for each bean
JComboBox<String> editCombo = new JComboBox<>();
editCombo.addItem(SET_TO_THROWN);
Expand Down Expand Up @@ -1929,7 +1929,7 @@ public void setValueAt(Object type, int r, int c) {
* @return A combobox containing the valid aspect names for this mast
*/
@Override
JComboBox getStateEditorBox(int row) {
JComboBox<String> getStateEditorBox(int row) {
// create dummy comboBox, override in extended classes for each bean
JComboBox<String> editCombo = new JComboBox<>();
editCombo.addItem(SET_TO_INACTIVE);
Expand Down Expand Up @@ -2086,7 +2086,7 @@ protected final void eventEditorMousePressed() {
* @return an appropriate combobox for this signal mast
*/
@Override
protected JComboBox getEditorBox(int row) {
protected JComboBox<String> getEditorBox(int row) {
return getAspectEditorBox(row);
}

Expand Down
9 changes: 2 additions & 7 deletions java/src/jmri/jmrit/vsdecoder/VSDecoderManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,7 @@ protected void registerReporterListener(String sysName) {
return;
}
jmri.NamedBeanHandle<Reporter> h = nbhm.getNamedBeanHandle(sysName, r);
if (h == null) {
return;
}

// Make sure we aren't already registered.
java.beans.PropertyChangeListener[] ll = r.getPropertyChangeListenersByReference(h.getName());
if (ll.length == 0) {
Expand All @@ -502,10 +500,7 @@ protected void registerBeanListener(Manager beanManager, String sysName) {
return;
}
jmri.NamedBeanHandle<NamedBean> h = nbhm.getNamedBeanHandle(sysName, b);
if (h == null) {
log.debug("no handle for bean {}", b.getDisplayName());
return;
}

// Make sure we aren't already registered.
java.beans.PropertyChangeListener[] ll = b.getPropertyChangeListenersByReference(h.getName());
if (ll.length == 0) {
Expand Down
9 changes: 2 additions & 7 deletions java/src/jmri/jmrit/withrottle/FastClockController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@ public void propertyChange(java.beans.PropertyChangeEvent e) {
}
};

if (fastClock == null) {
log.info("No fast clock manager instance.");
isValid = false;
return;
} else {
isValid = true;
}
isValid = true;

updateMinsSetpoint = (short)(fastClock.userGetRate() * UPDATE_MINUTES);
setReSyncSetpoint();
// request callback to update time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1304,17 +1304,6 @@ public void addNodeButtonActionPerformed() {

// all ready, create the new node
curNode = new SerialNode(nodeAddress, nodeType, _memo.getTrafficController());
// curNode cannot be null or an execption would have been thrown;
// what exceptions should this be catching (no documented exceptions are thrown by constructor)?
if (curNode == null) {
statusText1.setText(Bundle.getMessage("Error3"));
statusText1.setVisible(true);
JOptionPane.showMessageDialog(this, Bundle.getMessage("Error3") + Integer.toString(nodeAddress), "", JOptionPane.ERROR_MESSAGE);
log.error("Error creating Serial Node, constructor returned null");
errorInStatus1 = true;
resetNotes2();
return;
}
nodeTableModel.addRow(curNode);

// configure the new node
Expand Down
8 changes: 0 additions & 8 deletions java/src/jmri/jmrix/oaktree/nodeconfig/NodeConfigFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,6 @@ public void addButtonActionPerformed() {

// all ready, create the new node
curNode = new SerialNode(nodeAddress, nodeType, _memo);
if (curNode == null) {
statusText1.setText(Bundle.getMessage("Error3"));
statusText1.setVisible(true);
log.error("Error creating Serial Node, constructor returned null");
errorInStatus1 = true;
resetNotes2();
return;
}
// configure the new node
setNodeParameters();
log.debug("config node {} ready", nodeAddress);
Expand Down
8 changes: 0 additions & 8 deletions java/src/jmri/jmrix/secsi/nodeconfig/NodeConfigFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,6 @@ public void addButtonActionPerformed() {

// all ready, create the new node
curNode = new SerialNode(nodeAddress, nodeType, memo.getTrafficController());
if (curNode == null) {
statusText1.setText(Bundle.getMessage("Error3"));
statusText1.setVisible(true);
log.error("Error creating Serial Node, constructor returned null");
errorInStatus1 = true;
resetNotes2();
return;
}
// configure the new node
setNodeParameters();
// register any orphan sensors that this node may have
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrix/sprog/SprogTrafficController.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected synchronized void notifyReply(SprogReply r, SprogListener lastSender)
}

// A class to remember the message and who sent it
private class MessageTuple {
static private class MessageTuple {
private final SprogMessage message;
private final SprogListener listener;

Expand Down
8 changes: 2 additions & 6 deletions java/src/jmri/util/swing/ImagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected void paintComponent(Graphics g) {
imgWidth = back.getWidth(this);
imgHeight = back.getHeight(this);
double frameRatio = (double) getWidth() / (double) getHeight();
double imgRatio = imgWidth / imgHeight;
double imgRatio = (double) imgWidth / (double) imgHeight;
log.debug("ratios: fr {} - img {}", frameRatio, imgRatio);

// maintain squares on non square panels, enlarge to fill full frame
Expand All @@ -51,7 +51,7 @@ protected void paintComponent(Graphics g) {
// keep full imgWidth
imgHeight = (int) (imgWidth / frameRatio); // clip height
}
// clip part op back image
// clip part of back image
clip = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB);
clip = back.getSubimage(0, 0, Math.min(imgWidth, back.getWidth(this)),
Math.min(imgHeight, back.getHeight(this))); // catch clip size error on change to different pane
Expand All @@ -60,10 +60,6 @@ protected void paintComponent(Graphics g) {
}
}

//private void update() {
// repaint();
//}

private static final Logger log = LoggerFactory.getLogger(ImagePanel.class);

}
2 changes: 1 addition & 1 deletion java/src/jmri/web/servlet/about/AboutServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
response.setHeader("Connection", "Keep-Alive"); // NOI18N
response.setContentType(UTF8_TEXT_HTML);
Profile profile = ProfileManager.getDefault().getActiveProfile();
String profileName = profile != null ? profile.getName() : null;
String profileName = profile.getName();
response.getWriter().print(String.format(request.getLocale(),
FileUtil.readURL(FileUtil.findURL(Bundle.getMessage(request.getLocale(), "About.html"))),
Bundle.getMessage(request.getLocale(), "AboutTitle"), // page title is parm 1
Expand Down
2 changes: 1 addition & 1 deletion java/test/jmri/jmrix/nce/NceProgrammerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,6 @@ public void testReadRegisterSequenceBin() throws JmriException {
Assert.assertEquals(" value read", 20, l.getRcvdValue());
}

private final static Logger log = LoggerFactory.getLogger(NceProgrammerTest.class);
// private final static Logger log = LoggerFactory.getLogger(NceProgrammerTest.class);

}
5 changes: 2 additions & 3 deletions java/test/jmri/jmrix/sprog/SprogOpsModeProgrammerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public class SprogOpsModeProgrammerTest extends jmri.jmrix.AbstractOpsModeProgrammerTestBase {

private SprogTrafficControlScaffold stcs = null;
private SprogOpsModeProgrammer op = null;
private SprogSystemConnectionMemo m = null;

// The minimal setup for log4J
Expand All @@ -29,14 +28,14 @@ public void setUp() {
m.setSprogTrafficController(stcs);
m.configureCommandStation();

programmer = op = new SprogOpsModeProgrammer(2,false,m);
programmer = new SprogOpsModeProgrammer(2,false,m);
}

@After
public void tearDown() {
m.getSlotThread().interrupt();
stcs.dispose();
programmer = op = null;
programmer = null;
JUnitUtil.tearDown();
}

Expand Down
5 changes: 2 additions & 3 deletions java/test/jmri/jmrix/sprog/SprogProgrammerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class SprogProgrammerTest extends jmri.jmrix.AbstractProgrammerTest {

private SprogTrafficControlScaffold stcs = null;
private SprogProgrammer op = null;

@Test
@Override
Expand Down Expand Up @@ -50,13 +49,13 @@ public void setUp() {
stcs = new SprogTrafficControlScaffold(m);
m.setSprogTrafficController(stcs);

programmer = op = new SprogProgrammer(m);
programmer = new SprogProgrammer(m);
}

@After
public void tearDown() {
stcs.dispose();
programmer = op = null;
programmer = null;
JUnitUtil.tearDown();
}

Expand Down

0 comments on commit a05ecec

Please sign in to comment.