-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8277585: Remove the terminally deprecated finalize() method from javax.imageio.stream APIs #26650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back prr! A progress list of the required criteria for merging this PR into |
@prrace This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 134 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Webrevs
|
/label car |
/label csr |
@prrace
|
@prrace
|
src/java.desktop/share/classes/javax/imageio/stream/package-info.java
Outdated
Show resolved
Hide resolved
src/java.desktop/share/classes/javax/imageio/stream/FileCacheImageOutputStream.java
Outdated
Show resolved
Hide resolved
return; | ||
} | ||
try { | ||
cache.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice a similar nested class/method in FileCacheImageInputStream with a few differences. Does the cache.close() and cacheFile.delete need to be wrapped in null checks? And once deleted do the StreamDisposerRecord pointers (this.cacheFile and this.cache) need to be set to null like in the ImageInputStream version of the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I could re-use that. I just need to make it accessible .. but not public.
That one has null checks because it clears the vars.
My version uses a "disposed" var for the same since I made those vars final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of final
is recommended wherever possible, as the values are then guaranteed to be visible on other threads (e.g. the disposer thread).
However IIUC, values set in a DisposerRecord
by a program thread should (already) be visible on the disposer thread because Disposer.add()
and Disposer.run()
(via records.put()
and records.remove()
, respectively) lock the same records
Hashtable
object.
private final RandomAccessFile cache; | ||
private volatile boolean disposed; | ||
|
||
public FileCacheDisposerRecord(File cacheFile, RandomAccessFile cache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileCacheDisposer makes more sense based on what the code does, but would StreamDisposerRecord be better to remain consistent for the input/output streams?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, see comment below.
* A simple pattern would be | ||
* {@snippet lang='java': | ||
* try (FileOutputStream fos = new FileOutputStream("out.jpg"); | ||
* (ImageOutputStream ios = new FileCacheImageOutputStream(fos, null)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is an extra left parenthesis here at the start of the line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
* } // implicit finally block closes the streams in the reverse order to opening | ||
* } | ||
* <p> | ||
* Sub-classers of these Image I/O API stream types can to a limited extent protect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commas missing here
Sub-classers of these Image I/O API stream types can, to a limited extent, protect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can MemoryCacheImageOutputStream
be included in this PR?
Why ? It has nothing to dispose. |
Doesn't it have a
|
That just wraps an ArrayList<byte[]> |
The CSR is ready for review https://bugs.openjdk.org/browse/JDK-8364778 |
/integrate |
Going to push as commit 0858743.
Your commit was automatically rebased without conflicts. |
This PR removes javax/imageio/stream/ImageInputStreamImpl.finalize()
As a result, sub-classes which over-ride it to be empty no longer need to do so.
Also it means that the 2 remaining classes which used it no longer can.
FileCacheImageOutputStream will have its cache cleaned up by a disposer.
The impact on applications is that they, or the ImageWriter may need to call flush() IF they relied on finalization.
However that should be extremely unlikely given that finalization will happen far too late in most cases, and is
really meant to clean up internal resources.
The JDK's GIF and TIFF image writers don't flush themselves, so applications which use these together with one of these caching streams would have learned this already.
The principal outside risk is to 3rd party ImageIO stream subclasses which both allocate native resources and rely on finalization as a backstop clean up in case applications forget to call close. But it will be the applications that are affected if the resource is depleted.
The risks of this will be covered in the CSR.
There's also a lengthy write up in the JBS issue.
Progress
Issues
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26650/head:pull/26650
$ git checkout pull/26650
Update a local copy of the PR:
$ git checkout pull/26650
$ git pull https://git.openjdk.org/jdk.git pull/26650/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 26650
View PR using the GUI difftool:
$ git pr show -t 26650
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26650.diff
Using Webrev
Link to Webrev Comment