From b681480abb2c0a0a711faefcbbb0854e1104c5cc Mon Sep 17 00:00:00 2001 From: Mat Booth Date: Sun, 25 Jul 2021 10:56:48 +0100 Subject: [PATCH] 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 --- .../cdt/internal/core/model/ArchiveContainerInfo.java | 6 ++---- .../cdt/internal/core/model/BinaryContainerInfo.java | 6 ++---- .../eclipse/cdt/internal/core/model/CElementInfo.java | 10 +++++++++- 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()];