Commit 62b9c1d3 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

Fixed possible threading exception for reference chains


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 53f82990
......@@ -89,9 +89,11 @@ public final class ReferenceChain implements IReferenceChain {
@Override
/** {@inheritDoc} */
public void release() {
if (!chainLinks.isEmpty()) {
chainLinks.clear();
markedStates.clear();
synchronized (chainLinks) {
if (!chainLinks.isEmpty()) {
chainLinks.clear();
markedStates.clear();
}
}
CHAIN_CACHE.offer(this);
......@@ -106,13 +108,15 @@ public final class ReferenceChain implements IReferenceChain {
@Override
/** {@inheritDoc} */
public boolean add(final IReferenceChainElement chainLink) {
final int index = chainLinks.indexOf(chainLink);
if (index >= 0) {
reportError(index);
return false;
}
synchronized(chainLink) {
final int index = chainLinks.indexOf(chainLink);
if (index >= 0) {
reportError(index);
return false;
}
chainLinks.add(chainLink);
chainLinks.add(chainLink);
}
return true;
}
......@@ -163,8 +167,11 @@ public final class ReferenceChain implements IReferenceChain {
return;
}
final int markedLimit = polled.intValue();
for (int i = chainLinks.size() - 1; i >= markedLimit; i--) {
chainLinks.remove(i);
synchronized (chainLinks) {
for (int i = chainLinks.size() - 1; i >= markedLimit; i--) {
chainLinks.remove(i);
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment