diff options
author | Hannes Wellmann | 2021-05-06 09:04:38 +0000 |
---|---|---|
committer | Andrey Loskutov | 2021-05-06 10:25:22 +0000 |
commit | 928117b635b10bf83aa5bf516908a36ee4d6e879 (patch) | |
tree | adbf6dc125cdf636570e5f83158240531d08256a | |
parent | b8119693d8a0c48e398710eaad733c203e5eb3f5 (diff) | |
download | eclipse.platform.runtime-928117b635b10bf83aa5bf516908a36ee4d6e879.tar.gz eclipse.platform.runtime-928117b635b10bf83aa5bf516908a36ee4d6e879.tar.xz eclipse.platform.runtime-928117b635b10bf83aa5bf516908a36ee4d6e879.zip |
Bug 573396 - Make InternalPlatform.getLog() thread-safeS4_20_0_M3I20210526-0600I20210525-1800I20210525-0730I20210524-1800I20210524-0600I20210523-1800I20210523-0600I20210522-1800I20210522-0600I20210521-1800I20210521-0150I20210521-0110I20210519-1800I20210519-0600I20210518-1800I20210518-0850I20210518-0600I20210518-0200I20210517-1800I20210517-0600I20210516-1800I20210516-0600I20210515-1800I20210515-0600I20210514-1800I20210513-1800I20210512-2250I20210512-1800I20210511-1800I20210511-0740I20210511-0330I20210511-0200I20210510-1800I20210509-1800I20210508-1800I20210507-1800I20210506-1800
The method InternalPlatform.getLog(Bundle) was not guarded against
concurrent access. If multiple threads concurrently query a log the
'logs'-map could have ended in an inconsistent state.
However the ExtendedLogServiceFactory of the ExtendedLogService used to
create a new logger seems to be thread-safe.
Change-Id: Id12833936c32fce28f877292d5363152a4fccdbb
Signed-off-by: Hannes Wellmann <wellmann.hannes1@gmx.net>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.runtime/+/180289
Tested-by: Platform Bot <platform-bot@eclipse.org>
Reviewed-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r-- | bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java index 561f15d25..9c0b1cb15 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java @@ -19,6 +19,7 @@ package org.eclipse.core.internal.runtime; import java.io.File; import java.net.URL; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; import org.eclipse.core.internal.preferences.exchange.ILegacyPreferences; import org.eclipse.core.internal.preferences.exchange.IProductPreferencesService; import org.eclipse.core.internal.preferences.legacy.InitLegacyPreferences; @@ -60,8 +61,7 @@ public final class InternalPlatform { private static final String KEYRING = "-keyring"; //$NON-NLS-1$ private String keyringFile; - //XXX This is not synchronized - private Map<Bundle,Log> logs = new HashMap<>(5); + private Map<Bundle, Log> logs = new ConcurrentHashMap<>(5); private static final String[] OS_LIST = { Platform.OS_LINUX, Platform.OS_MACOSX, Platform.OS_WIN32 }; private String password = ""; //$NON-NLS-1$ @@ -355,16 +355,14 @@ public final class InternalPlatform { * The system log listener needs to be optional: turned on or off. What about a system property? :-) */ public ILog getLog(Bundle bundle) { - Log result = logs.get(bundle); - if (result != null) - return result; - ExtendedLogService logService = extendedLogTracker.getService(); - Logger logger = logService != null ? logService.getLogger(bundle, PlatformLogWriter.EQUINOX_LOGGER_NAME) : null; - result = new Log(bundle, logger); - ExtendedLogReaderService logReader = logReaderTracker.getService(); - logReader.addLogListener(result, result); - logs.put(bundle, result); - return result; + return logs.computeIfAbsent(bundle, b -> { + ExtendedLogService logService = extendedLogTracker.getService(); + Logger logger = logService != null ? logService.getLogger(b, PlatformLogWriter.EQUINOX_LOGGER_NAME) : null; + Log log = new Log(b, logger); + ExtendedLogReaderService logReader = logReaderTracker.getService(); + logReader.addLogListener(log, log); + return log; + }); } public String getNL() { |