Bug 574247 - Same binary file can appear multiple times

A race condition could sometimes yield duplicate entries in
the binary container due to interleaving of calls to
includesChild() and addChild()

Add a method to CElementInfo that can perform the check and
add the child atomically, by synchronising on the list of
children for the duration of the two operations.

Change-Id: I1ef1cddf3aad4934ec63cb433ebae34a77b69739
Signed-off-by: Mat Booth <mat.booth@gmail.com>
This commit is contained in:
Mat Booth 2021-07-25 10:56:48 +01:00
parent c33e81872d
commit b681480abb
3 changed files with 13 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* Copyright (c) 2000, 2021 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -36,8 +36,6 @@ public class ArchiveContainerInfo extends OpenableInfo {
@Override
protected void addChild(ICElement child) {
if (!includesChild(child)) {
super.addChild(child);
}
addChildIfAbsent(child);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 QNX Software Systems and others.
* Copyright (c) 2000, 2021 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -29,8 +29,6 @@ public class BinaryContainerInfo extends OpenableInfo {
@Override
protected void addChild(ICElement child) {
if (!includesChild(child)) {
super.addChild(child);
}
addChildIfAbsent(child);
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2009 QNX Software Systems and others.
* Copyright (c) 2000, 2021 QNX Software Systems and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@ -64,6 +64,14 @@ public class CElementInfo {
fChildren.add(child);
}
protected void addChildIfAbsent(ICElement child) {
synchronized (fChildren) {
if (!fChildren.contains(child)) {
fChildren.add(child);
}
}
}
protected ICElement[] getChildren() {
synchronized (fChildren) {
ICElement[] array = new ICElement[fChildren.size()];