Paul Bakker created FELIX-4361:
----------------------------------
Summary: Possible ConcurrentModificationException in
DependencyManager.getComponents()
Key: FELIX-4361
URL: https://issues.apache.org/jira/browse/FELIX-4361
Project: Felix
Issue Type: Bug
Components: Dependency Manager
Affects Versions: dependencymanager-3.1.0
Reporter: Paul Bakker
DependencyManager.getComponents() returns a unmodifiableList created as follows:
{code}
Collections.unmodifiableList(m_components);
{code}
However, this does not provide safe iteration on the result of calling this
method. E.g. the following can fail with a ConcurrentModificationException:
{code}
List<ComponentDeclaration> components = dm.getComponents();
for (ComponentDeclaration c : components) {
//do something
}
{code}
This is possible because the underlaying collection can be modified during
iteration. Wrapping it in an unmodifiable list doesn't prevent this, because
the modifications are done on the original list.
This can be fixed by copying the list to a new collection before returning.
This is more expensive, but the only way to be safe.
Patch and test provided.
--
This message was sent by Atlassian JIRA
(v6.1.4#6159)