Skip to content

Commit c45c9bf

Browse files
committed
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 apache#490
1 parent bb613ba commit c45c9bf

1 file changed

Lines changed: 28 additions & 19 deletions

File tree

engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,32 @@ private static void tagCommand(Command cmd) {
391391
}
392392
}
393393

394+
/**
395+
* @param commands
396+
* @return
397+
*/
398+
private Command[] checkForCommandsAndTag(Commands commands) {
399+
Command[] cmds = commands.toCommands();
400+
401+
assert cmds.length > 0 : "Ask yourself this about a hundred times. Why am I sending zero length commands?";
402+
403+
setEmptyAnswers(commands, cmds);
404+
405+
for (Command cmd : cmds)
406+
tagCommand(cmd);
407+
return cmds;
408+
}
409+
410+
/**
411+
* @param commands
412+
* @param cmds
413+
*/
414+
private void setEmptyAnswers(Commands commands, Command[] cmds) {
415+
if (cmds.length == 0) {
416+
commands.setAnswers(new Answer[0]);
417+
}
418+
}
419+
394420
@Override
395421
public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUnavailableException, OperationTimedoutException {
396422
assert hostId != null : "Who's not checking the agent id before sending? ... (finger wagging)";
@@ -412,16 +438,7 @@ public Answer[] send(Long hostId, Commands commands, int timeout) throws AgentUn
412438
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!";
413439
}
414440

415-
Command[] cmds = commands.toCommands();
416-
417-
assert cmds.length > 0 : "Ask yourself this about a hundred times. Why am I sending zero length commands?";
418-
419-
if (cmds.length == 0) {
420-
commands.setAnswers(new Answer[0]);
421-
}
422-
423-
for (Command cmd : cmds)
424-
tagCommand(cmd);
441+
Command[] cmds = checkForCommandsAndTag(commands);
425442

426443
final AgentAttache agent = getAttache(hostId);
427444
if (agent == null || agent.isClosed()) {
@@ -476,15 +493,7 @@ public long send(Long hostId, Commands commands, Listener listener) throws Agent
476493
throw new AgentUnavailableException("Agent " + agent.getId() + " is closed", agent.getId());
477494
}
478495

479-
Command[] cmds = commands.toCommands();
480-
481-
assert cmds.length > 0 : "Why are you sending zero length commands?";
482-
if (cmds.length == 0) {
483-
throw new AgentUnavailableException("Empty command set for agent " + agent.getId(), agent.getId());
484-
}
485-
486-
for (Command cmd : cmds)
487-
tagCommand(cmd);
496+
Command[] cmds = checkForCommandsAndTag(commands);
488497

489498
Request req = new Request(hostId, agent.getName(), _nodeId, cmds, commands.stopOnError(), true);
490499
req.setSequence(agent.getNextSequence());

0 commit comments

Comments
 (0)