findbugs UC useless condition not sure what findbugs means yet, but this should at least turn both warnings into one.

Signed-off-by: Daan Hoogland <daan@onecht.net>

This closes #490
This commit is contained in:
Daan Hoogland 2015-06-19 13:38:45 +02:00
parent bb613baa2b
commit c45c9bfeef

View File

@ -391,6 +391,32 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
} }
} }
/**
* @param commands
* @return
*/
private Command[] checkForCommandsAndTag(Commands commands) {
Command[] cmds = commands.toCommands();
assert cmds.length > 0 : "Ask yourself this about a hundred times. Why am I sending zero length commands?";
setEmptyAnswers(commands, cmds);
for (Command cmd : cmds)
tagCommand(cmd);
return cmds;
}
/**
* @param commands
* @param cmds
*/
private void setEmptyAnswers(Commands commands, Command[] cmds) {
if (cmds.length == 0) {
commands.setAnswers(new Answer[0]);
}
}
@Override @Override
public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException { public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
assert hostId != null : "Who's not checking the agent id before sending? ... (finger wagging)"; assert hostId != null : "Who's not checking the agent id before sending? ... (finger wagging)";
@ -412,16 +438,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
assert noDbTxn() : "I know, I know. Why are we so strict as to not allow txn across an agent call? ... Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!"; assert noDbTxn() : "I know, I know. Why are we so strict as to not allow txn across an agent call? ... Why are we so cruel ... Why are we such a dictator .... Too bad... Sorry...but NO AGENT COMMANDS WRAPPED WITHIN DB TRANSACTIONS!";
} }
Command[] cmds = commands.toCommands(); Command[] cmds = checkForCommandsAndTag(commands);
assert cmds.length > 0 : "Ask yourself this about a hundred times. Why am I sending zero length commands?";
if (cmds.length == 0) {
commands.setAnswers(new Answer[0]);
}
for (Command cmd : cmds)
tagCommand(cmd);
final AgentAttache agent = getAttache(hostId); final AgentAttache agent = getAttache(hostId);
if (agent == null || agent.isClosed()) { if (agent == null || agent.isClosed()) {
@ -476,15 +493,7 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl
throw new AgentUnavailableException("Agent " + agent.getId() + " is closed", agent.getId()); throw new AgentUnavailableException("Agent " + agent.getId() + " is closed", agent.getId());
} }
Command[] cmds = commands.toCommands(); Command[] cmds = checkForCommandsAndTag(commands);
assert cmds.length > 0 : "Why are you sending zero length commands?";
if (cmds.length == 0) {
throw new AgentUnavailableException("Empty command set for agent " + agent.getId(), agent.getId());
}
for (Command cmd : cmds)
tagCommand(cmd);
Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true); Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
req.setSequence(agent.getNextSequence()); req.setSequence(agent.getNextSequence());