From 6307344e3b129409ca7d2f0694224bc3d832fd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Porras=20Campo?= Date: Fri, 29 Nov 2024 16:22:21 +0100 Subject: [PATCH] use proper Double-checked locking --- .../xtext/layered/DefaultXtextTargetPlatform.java | 13 ++++++++++--- .../PatternAwareEObjectDescriptionLookUp.java | 9 +++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/layered/DefaultXtextTargetPlatform.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/layered/DefaultXtextTargetPlatform.java index 5122d2245..f63490367 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/layered/DefaultXtextTargetPlatform.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/layered/DefaultXtextTargetPlatform.java @@ -32,10 +32,17 @@ public class DefaultXtextTargetPlatform implements IXtextTargetPlatform { @Override public IResourceDescriptionsData getIResourceDescriptionsData() { - if (index == null) { - index = new DelegatingResourceDescriptionsData(new ResourceDescriptionsData(Collections.emptyList())); + IResourceDescriptionsData localRef = index; + if (localRef == null) { + synchronized (this) { + localRef = index; + if (localRef == null) { + localRef = new DelegatingResourceDescriptionsData(new ResourceDescriptionsData(Collections.emptyList())); + index = localRef; + } + } } - return index; + return localRef; } @Override diff --git a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/PatternAwareEObjectDescriptionLookUp.java b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/PatternAwareEObjectDescriptionLookUp.java index d9f7979d6..8f269e754 100644 --- a/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/PatternAwareEObjectDescriptionLookUp.java +++ b/com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/PatternAwareEObjectDescriptionLookUp.java @@ -86,13 +86,14 @@ protected Map> getNameToObjects() { } protected QualifiedNameLookup getNameToObjectsLookup() { - if (nameToObjectsLookup == null) { + QualifiedNameLookup localMap = nameToObjectsLookup; + if (localMap == null) { synchronized (this) { // CHECKSTYLE:OFF with volatile it is ok - if (nameToObjectsLookup == null) { + if (localMap == null) { // CHECKSTYLE:ON with volatile it is ok Iterable allDescriptions = getExportedObjects(); - QualifiedNameLookup localMap = QualifiedNameSegmentTreeLookup.createNameLookupCache("PatternAwareEObjectDescriptionLookUp#localMap", IEObjectDescription.class, false); //$NON-NLS-1$ + localMap = QualifiedNameSegmentTreeLookup.createNameLookupCache("PatternAwareEObjectDescriptionLookUp#localMap", IEObjectDescription.class, false); //$NON-NLS-1$ if (allDescriptions instanceof RandomAccess) { List asList = (List) allDescriptions; for (IEObjectDescription description : asList) { @@ -107,7 +108,7 @@ protected QualifiedNameLookup getNameToObjectsLookup() { } } } - return this.nameToObjectsLookup; + return localMap; } }