-
Type:
Sub-task
-
Resolution: Unresolved
-
Priority:
P4
-
Affects Version/s: 27
-
Component/s: core-libs
The `ThreadPoolExecutor.finalize()` method has been removed. It was deprecated for removal in JDK 18.
All Java classes can inherit the `Object.finalize()` method, which is declared to throw `Throwable`. However `ThreadPoolExecutor` overrode `finalize()` to *not* throw an exception.
With the removal of `ThreadPoolExecutor.finalize()`, any existing code that extends `ThreadPoolExecutor` and overrides `finalize()` to call `super.finalize()` (or calls `finalize()` directly) will now be calling `Object.finalize()`. If such code does not account for `Throwable`, it will encounter an "`unreported exception Throwable`" compilation error. This can be addressed by updating affected methods to throw `Throwable`, or with a *try-catch* block.
Note that as of [JEP 421](https://openjdk.org/jeps/421), all code should stop using finalizers.
All Java classes can inherit the `Object.finalize()` method, which is declared to throw `Throwable`. However `ThreadPoolExecutor` overrode `finalize()` to *not* throw an exception.
With the removal of `ThreadPoolExecutor.finalize()`, any existing code that extends `ThreadPoolExecutor` and overrides `finalize()` to call `super.finalize()` (or calls `finalize()` directly) will now be calling `Object.finalize()`. If such code does not account for `Throwable`, it will encounter an "`unreported exception Throwable`" compilation error. This can be addressed by updating affected methods to throw `Throwable`, or with a *try-catch* block.
Note that as of [JEP 421](https://openjdk.org/jeps/421), all code should stop using finalizers.