Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTorbjörn SVENSSON2021-11-15 10:52:11 +0000
committerSarika Sinha2021-11-17 18:29:19 +0000
commitf3956032ba74e6bcb3729a5ba805497fe59c76c3 (patch)
treeb51b4094f5c79b8f8b0e64f620e44a2c99d72961
parenta7533bd84d2276ba3180174559cb3a25d3430db8 (diff)
downloadeclipse.platform.debug-f3956032ba74e6bcb3729a5ba805497fe59c76c3.tar.gz
eclipse.platform.debug-f3956032ba74e6bcb3729a5ba805497fe59c76c3.tar.xz
eclipse.platform.debug-f3956032ba74e6bcb3729a5ba805497fe59c76c3.zip
There was a race between checking the fThread for null and seting it to null. This could lead to that two parallel calls to close() could be made and the 2nd call would get an NPE. Change-Id: Ia107f6c84c4092a09027c691646e343d400ca6d4 Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com> Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.debug/+/187734 Reviewed-by: Jonah Graham <jonah@kichwacoders.com> Reviewed-by: Sarika Sinha <sarika.sinha@in.ibm.com> Tested-by: Sarika Sinha <sarika.sinha@in.ibm.com>
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java19
-rw-r--r--org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java28
2 files changed, 30 insertions, 17 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java
index 7ed21a6ea..d0525f642 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/InputStreamMonitor.java
@@ -131,10 +131,12 @@ public class InputStreamMonitor {
* Starts a thread which writes the stream.
*/
public void startMonitoring() {
- if (fThread == null) {
- fThread = new Thread((Runnable) this::write, DebugCoreMessages.InputStreamMonitor_label);
- fThread.setDaemon(true);
- fThread.start();
+ synchronized (this) {
+ if (fThread == null) {
+ fThread = new Thread((Runnable) this::write, DebugCoreMessages.InputStreamMonitor_label);
+ fThread.setDaemon(true);
+ fThread.start();
+ }
}
}
@@ -143,9 +145,12 @@ public class InputStreamMonitor {
* monitor and the underlying stream.
*/
public void close() {
- if (fThread != null) {
- Thread thread= fThread;
- fThread= null;
+ Thread thread = null;
+ synchronized (this) {
+ thread = fThread;
+ fThread = null;
+ }
+ if (thread != null) {
thread.interrupt();
}
}
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
index bdc2cd539..3a6f1a41c 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/OutputStreamMonitor.java
@@ -134,15 +134,21 @@ public class OutputStreamMonitor implements IBinaryStreamMonitor {
* underlying stream by waiting for the thread to terminate.
*/
protected void close() {
- if (fThread != null) {
- Thread thread = fThread;
+ Thread thread = null;
+
+ synchronized (this) {
+ thread = fThread;
fThread = null;
+ }
+
+ if (thread != null) {
try {
thread.join();
} catch (InterruptedException ie) {
}
- fListeners = new ListenerList<>();
- fBinaryListeners = new ListenerList<>();
+
+ fListeners.clear();
+ fBinaryListeners.clear();
}
}
@@ -304,12 +310,14 @@ public class OutputStreamMonitor implements IBinaryStreamMonitor {
* Starts a thread which reads from the stream
*/
protected void startMonitoring() {
- if (fThread == null) {
- fDone.set(false);
- fThread = new Thread((Runnable) this::read, DebugCoreMessages.OutputStreamMonitor_label);
- fThread.setDaemon(true);
- fThread.setPriority(Thread.MIN_PRIORITY);
- fThread.start();
+ synchronized (this) {
+ if (fThread == null) {
+ fDone.set(false);
+ fThread = new Thread((Runnable) this::read, DebugCoreMessages.OutputStreamMonitor_label);
+ fThread.setDaemon(true);
+ fThread.setPriority(Thread.MIN_PRIORITY);
+ fThread.start();
+ }
}
}

Back to the top