Skip to content

Commit

Permalink
fix ConcurrentModificationException in sendStatusTick
Browse files Browse the repository at this point in the history
  • Loading branch information
fmessmer committed Sep 15, 2018
1 parent 4854154 commit 1864836
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main/java/com/github/rosjava_actionlib/ActionServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,20 @@ public void sendStatusTick() {
GoalStatus goalStatus;
Vector<GoalStatus> goalStatusList = new Vector<GoalStatus>();

for (ServerGoal sg : goalTracker.values()) {
goalStatus = node.getTopicMessageFactory().newFromType(GoalStatus._TYPE);
goalStatus.setGoalId(getGoalId(sg.goal));
goalStatus.setStatus((byte) sg.state.getState());
goalStatusList.add(goalStatus);
try {
for(java.util.Iterator<ServerGoal> sgIterator = goalTracker.values().iterator(); sgIterator.hasNext();) {
ServerGoal sg = sgIterator.next();
goalStatus = node.getTopicMessageFactory().newFromType(GoalStatus._TYPE);
goalStatus.setGoalId(getGoalId(sg.goal));
goalStatus.setStatus((byte) sg.state.getState());
goalStatusList.add(goalStatus);
}
} catch (java.util.ConcurrentModificationException exception) {
exception.printStackTrace(System.out);
} catch (Throwable throwable) {
throwable.printStackTrace(System.out);
}

status.setStatusList(goalStatusList);
sendStatus(status);
}
Expand Down Expand Up @@ -316,6 +324,7 @@ public void setSucceed(String goalIdString) {
try {
goalTracker.get(goalIdString).state.transition(ServerStateMachine.Events.SUCCEED);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}

Expand All @@ -327,6 +336,7 @@ public void setPreempt(String goalIdString) {
goalTracker.get(goalIdString).state.transition(ServerStateMachine.Events.CANCEL_REQUEST);
goalTracker.get(goalIdString).state.transition(ServerStateMachine.Events.CANCEL);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}

Expand All @@ -337,6 +347,7 @@ public void setAbort(String goalIdString) {
try {
goalTracker.get(goalIdString).state.transition(ServerStateMachine.Events.ABORT);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}

Expand All @@ -353,6 +364,7 @@ public void setGoalStatus(GoalStatus gstat, String gidString) {
gstat.setGoalId(getGoalId(serverGoal.goal));
gstat.setStatus((byte) serverGoal.state.getState());
} catch (Exception e) {
e.printStackTrace(System.out);
}
}

Expand Down

0 comments on commit 1864836

Please sign in to comment.