8362898: Remove finalize() methods from javax.imagio TIFF classes. #26416
+40
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Remove finalize from TIFF ImageIO implementatation classes.
Following copied from the bug description
The TIFF image (de)compressors can make use of a JPEG reader / writer
Like all ImageIO readers and writers, once done, the owner should call their dispose() method.
This is currently done with finalize() to ensure it isn't missed.
This can be migrated to a Disposer.
However, the most common case is that it is the ImageIO built-in JPEGImageReader and JPEGImageWriter
that is located and that already implements a Disposer. So there is no need to add a Disposer for that.
We only need to add it if we find some other reader/writer.
With enough work, it might be possible for the TIFF compressor/decompressor classes to work out when
they are really done and avoid a Disposer at all. But it could also be that they instead need to discard
them when a specific task is done and then obtain a new one.
That would be much more overhead than just adding a Disposer for the rare case and regardless
of what is done in the TIFF code, the built in JPEG classes will install their own Disposer so I don't
think I want to pursue that route.
I also noticed that TIFFBaseJPEGCompressor.java can replace the current writer if it doesn't satisfy a need.
In that case it just nulls it out and doesn't call dispose() and of course finalize() will then refer to the replacement.
So I added direct calls to dispose() in such a case. That was definitely necessary with the finalize() code
but the Disposer would have taken care of it anyway, so it isn't strictly needed with the new code but
it is still good to do it early if you can.
Progress
Warning
8362898: Remove finalize() methods from javax.imagio TIFF classes.
Issue
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26416/head:pull/26416
$ git checkout pull/26416
Update a local copy of the PR:
$ git checkout pull/26416
$ git pull https://git.openjdk.org/jdk.git pull/26416/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26416
View PR using the GUI difftool:
$ git pr show -t 26416
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26416.diff
Using Webrev
Link to Webrev Comment