Skip to content

Commit 6d06b55

Browse files
committed
Stop dealing with ThreadDeath
Java 20+ Thread.stop throws UnsupportedOperationException and thus ThreadDeath is not thrown by anything anymore. Stop dealing with it. https://inside.java/2022/11/09/quality-heads-up/
1 parent ec5992a commit 6d06b55

File tree

7 files changed

+24
-64
lines changed

7 files changed

+24
-64
lines changed

bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/IEventLoopAdvisor.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2011, 2015 IBM Corporation and others.
2+
* Copyright (c) 2011, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -39,27 +39,26 @@ public interface IEventLoopAdvisor {
3939
public void eventLoopIdle(Display display);
4040

4141
/**
42-
* Performs arbitrary actions when the event loop crashes (the code that
43-
* handles a UI event throws an exception that is not caught).
42+
* Performs arbitrary actions when the event loop crashes (the code that handles
43+
* a UI event throws an exception that is not caught).
4444
* <p>
45-
* This method is called when the code handling a UI event throws an
46-
* exception. In a perfectly functioning application, this method would
47-
* never be called. In practice, it comes into play when there are bugs in
48-
* the code that trigger unchecked runtime exceptions. It is also activated
49-
* when the system runs short of memory, etc. Fatal errors (ThreadDeath) are
50-
* not passed on to this method, as there is nothing that could be done.
45+
* This method is called when the code handling a UI event throws an exception.
46+
* In a perfectly functioning application, this method would never be called. In
47+
* practice, it comes into play when there are bugs in the code that trigger
48+
* unchecked runtime exceptions. It is also activated when the system runs short
49+
* of memory, etc. Fatal errors are not passed on to this method, as there is
50+
* nothing that could be done.
5151
* </p>
5252
* <p>
53-
* Clients must not call this method directly (although super calls are
54-
* okay). The default implementation logs the problem so that it does not go
55-
* unnoticed. Subclasses may override or extend this method. It is generally
56-
* a bad idea to override with an empty method, and you should be especially
57-
* careful when handling Errors.
53+
* Clients must not call this method directly (although super calls are okay).
54+
* The default implementation logs the problem so that it does not go unnoticed.
55+
* Subclasses may override or extend this method. It is generally a bad idea to
56+
* override with an empty method, and you should be especially careful when
57+
* handling Errors.
5858
* </p>
5959
*
60-
* @param exception
61-
* the uncaught exception that was thrown inside the UI event
62-
* loop
60+
* @param exception the uncaught exception that was thrown inside the UI event
61+
* loop
6362
*/
6463
public void eventLoopException(Throwable exception);
6564
}

bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/PartRenderingEngine.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2019 IBM Corporation and others.
2+
* Copyright (c) 2008, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -1151,8 +1151,6 @@ public void eventLoopException(Throwable exception) {
11511151
}
11521152
advisor.eventLoopIdle(display);
11531153
}
1154-
} catch (ThreadDeath th) {
1155-
throw th;
11561154
} catch (Exception | Error err) {
11571155
handle(err, advisor);
11581156
}
@@ -1166,10 +1164,6 @@ private void handle(Throwable ex, IEventLoopAdvisor advisor) {
11661164
try {
11671165
advisor.eventLoopException(ex);
11681166
} catch (Throwable t) {
1169-
if (t instanceof ThreadDeath) {
1170-
throw (ThreadDeath) t;
1171-
}
1172-
11731167
// couldn't handle the exception, print to console
11741168
t.printStackTrace();
11751169
}

bundles/org.eclipse.jface/src/org/eclipse/jface/operation/ModalContext.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -122,10 +122,6 @@ public void run() {
122122
if (runnable != null) {
123123
runnable.run(progressMonitor);
124124
}
125-
} catch (ThreadDeath e) {
126-
// Make sure to propagate ThreadDeath, or threads will never
127-
// fully terminate.
128-
throw e;
129125
} catch (InvocationTargetException | InterruptedException | RuntimeException | Error e) {
130126
throwable = e;
131127
} finally {
@@ -170,12 +166,6 @@ public void block() {
170166
}
171167
exceptionCount = 0;
172168
}
173-
// ThreadDeath is a normal error when the thread is dying.
174-
// We must propagate it in order for it to properly
175-
// terminate.
176-
catch (ThreadDeath e) {
177-
throw (e);
178-
}
179169
// For all other exceptions, log the problem.
180170
catch (Throwable t) {
181171
if (t instanceof VirtualMachineError) {
@@ -414,10 +404,6 @@ public static void run(IRunnableWithProgress operation, boolean fork,
414404
static Throwable invokeThreadListener(IThreadListener listener, Thread switchingThread) {
415405
try {
416406
listener.threadChange(switchingThread);
417-
} catch (ThreadDeath e) {
418-
// Make sure to propagate ThreadDeath, or threads will never
419-
// fully terminate
420-
throw e;
421407
} catch (RuntimeException | Error e) {
422408
return e;
423409
}
@@ -438,9 +424,7 @@ private static void runInCurrentThread(IRunnableWithProgress runnable, IProgress
438424
InterruptedException interruptedException = new InterruptedException(e.getLocalizedMessage());
439425
interruptedException.initCause(e);
440426
throw interruptedException;
441-
} catch (InvocationTargetException | InterruptedException | ThreadDeath e) {
442-
// Make sure to propagate ThreadDeath, or threads will never fully
443-
// terminate.
427+
} catch (InvocationTargetException | InterruptedException e) {
444428
throw e;
445429
} catch (RuntimeException | Error e) {
446430
throw new InvocationTargetException(e);

bundles/org.eclipse.jface/src/org/eclipse/jface/window/Window.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -129,11 +129,6 @@ public static interface IExceptionHandler {
129129
private static class DefaultExceptionHandler implements IExceptionHandler {
130130
@Override
131131
public void handleException(Throwable t) {
132-
if (t instanceof ThreadDeath) {
133-
// Don't catch ThreadDeath as this is a normal occurrence when
134-
// the thread dies
135-
throw (ThreadDeath) t;
136-
}
137132
// Try to keep running.
138133
t.printStackTrace();
139134
}

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/application/WorkbenchAdvisor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ public void postShutdown() {
280280
* In a perfectly functioning application, this method would never be called. In
281281
* practice, it comes into play when there are bugs in the code that trigger
282282
* unchecked runtime exceptions. It is also activated when the system runs short
283-
* of memory, etc. Fatal errors (ThreadDeath) are not passed on to this method,
284-
* as there is nothing that could be done.
283+
* of memory, etc. Fatal errors are not passed on to this method, as there is
284+
* nothing that could be done.
285285
* </p>
286286
* <p>
287287
* Clients must not call this method directly (although super calls are okay).

bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/ExceptionHandler.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2015 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,8 +17,7 @@
1717

1818
/**
1919
* This handler will pass along to the workbench advisor exceptions and errors
20-
* thrown while running the event loop. However, the <code>ThreadDeath</code>
21-
* error is simply thrown again, and is not passed along.
20+
* thrown while running the event loop.
2221
*/
2322
public final class ExceptionHandler implements Window.IExceptionHandler {
2423

@@ -42,11 +41,6 @@ private ExceptionHandler() {
4241
@Override
4342
public void handleException(Throwable t) {
4443
try {
45-
// Ignore ThreadDeath error as its normal to get this when thread dies
46-
if (t instanceof ThreadDeath) {
47-
throw (ThreadDeath) t;
48-
}
49-
5044
// Check to avoid recursive errors
5145
exceptionCount++;
5246
if (exceptionCount > 2) {

tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/PartRenderingEngineTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,6 @@ private void handle(Throwable ex, IEventLoopAdvisor advisor) {
151151
try {
152152
advisor.eventLoopException(ex);
153153
} catch (Throwable t) {
154-
// The type ThreadDeath has been deprecated since version 20
155-
// and marked for removal
156-
if ("ThreadDeath".equals(t.getClass().getSimpleName())) {
157-
// don't catch ThreadDeath by accident
158-
throw t;
159-
}
160154
// couldn't handle the exception, print to console
161155
t.printStackTrace();
162156
} finally {

0 commit comments

Comments
 (0)