Skip to content

Make ExecutionEnvironment thread safe#867

Merged
iloveeclipse merged 3 commits intoeclipse-jdt:masterfrom
iloveeclipse:CME_in_EE
Feb 28, 2026
Merged

Make ExecutionEnvironment thread safe#867
iloveeclipse merged 3 commits intoeclipse-jdt:masterfrom
iloveeclipse:CME_in_EE

Conversation

@iloveeclipse
Copy link
Member

  • replaced method level lock on getParticipants() with inner lock with smaller scope
  • guard all (cross connected) maps & fields etc write access with the lock on EE
  • made some maps concurrent where read access was required outside the lock
  • made fields volatile where needed

Beside this, some cleanup in extra commit to get rid of useless code.

Fixes #865

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes the ExecutionEnvironment class thread-safe to fix a ConcurrentModificationException reported in issue #865. The changes address race conditions by introducing synchronized blocks, concurrent collections, and volatile fields to protect shared mutable state accessed by multiple threads.

Changes:

  • Replaced standard collections with thread-safe alternatives: ConcurrentHashMap.newKeySet() for fStrictlyCompatible and CopyOnWriteArrayList for fCompatibleVMs
  • Added synchronized(this) blocks to protect compound operations on shared state (maps, lists, caches)
  • Made lazy-initialized fields volatile (fPropertiesInitialized, fDefault, fParticipants) to support safe double-checked locking
  • Removed obsolete Javadoc comments and redundant field initialization
Comments suppressed due to low confidence (1)

org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/ExecutionEnvironment.java:295

  • The check at line 289 (fCompatibleVMs.contains(vm)) occurs outside of synchronization, but fCompatibleVMs is a CopyOnWriteArrayList which can be modified concurrently by add() and remove() methods. While CopyOnWriteArrayList is thread-safe for its operations, this creates a time-of-check-time-of-use (TOCTOU) race condition: the VM could be removed from fCompatibleVMs between the contains() check and when fDefault is set (line 295), allowing an incompatible VM to become the default. Consider moving the contains() check inside a synchronized block or using the volatile fDefault with proper synchronization.
	public void setDefaultVM(IVMInstall vm) {
		init();
		if (vm != null && !fCompatibleVMs.contains(vm)) {
			throw new IllegalArgumentException(NLS.bind(EnvironmentMessages.EnvironmentsManager_0, getId()));
		}
		if (vm != null && vm.equals(fDefault)) {
			return;
		}
		fDefault = vm;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- removed non javadoc comments
- removed default init from fields
- replaced method level lock on getParticipants() with inner lock with
smaller scope
- guard all (cross connected) maps & fields etc write access with the
lock on EE
- made some maps concurrent where read access was required outside the
lock
- made fields volatile where needed

Fixes eclipse-jdt#865
@eclipse-jdt-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

org.eclipse.jdt.launching/META-INF/MANIFEST.MF
org.eclipse.jdt.launching/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From dff4334efeafc65b8ac3754eda66334d8cf2170a Mon Sep 17 00:00:00 2001
From: Eclipse JDT Bot <jdt-bot@eclipse.org>
Date: Fri, 27 Feb 2026 22:19:29 +0000
Subject: [PATCH] Version bump(s) for 4.40 stream


diff --git a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
index 005a413dc..3a986e897 100644
--- a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.launching; singleton:=true
-Bundle-Version: 3.24.100.qualifier
+Bundle-Version: 3.24.200.qualifier
 Bundle-Activator: org.eclipse.jdt.internal.launching.LaunchingPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/org.eclipse.jdt.launching/pom.xml b/org.eclipse.jdt.launching/pom.xml
index 3017897be..8de6e6092 100644
--- a/org.eclipse.jdt.launching/pom.xml
+++ b/org.eclipse.jdt.launching/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.launching</artifactId>
-  <version>3.24.100-SNAPSHOT</version>
+  <version>3.24.200-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
   
   <build>
-- 
2.53.0

Further information are available in Common Build Issues - Missing version increments.

@iloveeclipse iloveeclipse merged commit 6da0f46 into eclipse-jdt:master Feb 28, 2026
12 of 13 checks passed
@iloveeclipse iloveeclipse deleted the CME_in_EE branch February 28, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CME under JREContainerInitializer.resolveVM

3 participants