Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMat Booth2021-07-25 09:56:48 +0000
committerMat Booth2021-07-25 10:03:01 +0000
commitb681480abb2c0a0a711faefcbbb0854e1104c5cc (patch)
tree99b0d0e8614d418c23143e89119938d60e3bae2d
parentc33e81872d3dc5f05fec87e2a7cac77f3ed17656 (diff)
downloadorg.eclipse.cdt-b681480abb2c0a0a711faefcbbb0854e1104c5cc.tar.gz
org.eclipse.cdt-b681480abb2c0a0a711faefcbbb0854e1104c5cc.tar.xz
org.eclipse.cdt-b681480abb2c0a0a711faefcbbb0854e1104c5cc.zip
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>
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java6
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java6
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java10
3 files changed, 13 insertions, 9 deletions
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java
index bd79fed2ed7..23788a58cc5 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ArchiveContainerInfo.java
@@ -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);
}
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java
index 07340c2d67c..4196d3a8db3 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/BinaryContainerInfo.java
@@ -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);
}
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
index 8e0e70f69e0..88a44167a80 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElementInfo.java
@@ -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()];

Back to the top