Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[1174841] UnsupportedOperationException on mergeInventoryReport()
Browse files Browse the repository at this point in the history
Avoid the use of Iterator.remove() because Resources coming from the
Agent may be using a customized impl for Resource.childResources (like
CopyOnWriteArraySet).  The solution "lazily protects" because the
problem scenario is rare (restype reported by agent is not
present on the server) and we don't want to do any unnecessary work (like
changing the Set impl in advance).

(cherry picked from commit 9c37410)
  • Loading branch information
jshaughn authored and Michael Burman committed Dec 19, 2014
1 parent 9844299 commit 6a4db38
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -1329,12 +1329,19 @@ private boolean initResourceTypes(Resource resource, Map<String, ResourceType> l
return true;
}

// bz1174841 protect against the case where resource.hasCustomChildResourcesCollection() is true and the
// custom collection does not support Iterator.remove(). (note, just uses an approach that works in all cases.)
Set<Resource> badChildren = null;
for (Iterator<Resource> childIterator = resource.getChildResources().iterator(); childIterator.hasNext();) {
Resource child = childIterator.next();
if (!initResourceTypes(child, loadedTypeMap)) {
childIterator.remove();
badChildren = (null == badChildren) ? new HashSet<Resource>() : badChildren;
badChildren.add(child);
}
}
if (null != badChildren) {
resource.getChildResources().removeAll(badChildren);
}

return true;
}
Expand Down

0 comments on commit 6a4db38

Please sign in to comment.