-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8319925: CSS.BackgroundImage incorrectly uses double-checked locking #16917
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 psadhukhan! A progress list of the required criteria for merging this PR into |
Webrevs
|
@prsadhuk 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 177 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 |
That code does not look like double-checked lock, it is something different. It checks/init/sets one field and then returns another one. Even if both will be marked as volatile the method may return null, since the loadedImage is set to true before init of image. |
I think the field |
Yep. It is a DCL, essentially, but it uses a different field to protect access to another field whereas the classic DCL uses the same field that it protects.
This is correct. Good catch! I missed it. For correctness, the assignment
has to be moved below the if-statement: if (!loadedImage) {
URL url = CSS.getURL(base, svalue);
if (url != null) {
image = new ImageIcon();
Image tmpImg = Toolkit.getDefaultToolkit().createImage(url);
if (tmpImg != null) {
image.setImage(tmpImg);
}
}
loadedImage = true;
} Otherwise, the returned |
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.
Based on my recent comment, the code needs updating.
Thanks @mrserb for catching another mistake.
It is probably easy just drop the usage of loadedImage and use the image instead? |
Ideally. Yet there's a corner case: if |
Not sure how it is expected to work, the url is a parameter and can be changed on the fly(see the usage of base in the StyleSheet.java) |
Yes, seems like setBase can be used to change image URL on the fly...Modified to use image field for DCL... |
I am against this latest change: it doesn't fix much but it would cause creating the URL each time Usually, This is asymmetric: in one case, it's re-loaded, in another — it isn't. I'm for keeping the current behaviour: if the URL is invalid, the image isn't loaded and will never be for this instance of |
As per your change, if URL is invalid ie url = null, image is not loaded but |
Exactly! The image is never given a chance to load for a second time. It is how the code has always worked. With your proposed change, the image has a chance to re-load if and only if I do not think this is correct or desirable. |
But it can be a bug in the code that it never gave a chance second time..I think it should get a chance to reload the URL again in case it is invalid the 1st time so I guess the change should be the one where if url is invalid,
|
My point is it must re-load the image whenever base is changed, as @mrserb pointed out. If you want to implement this feature, submit a new bug — it is out of scope for this issue. Better yet, just submit the new bug to document the discovered problem. Re-loading the image if and only if the Currently, it's in never mode. I am for preserving the current behaviour rather than adding a half-baked solution. |
OK. I have had my doubts but I agree to keep it as similar to code we have it now..Modified the PR.. |
/integrate |
Going to push as commit 0b0fa47.
Your commit was automatically rebased without conflicts. |
CSS.BackgroundImage.getImage uses double-checked locking but the loadedImage field isn't declared as volatile. Without the volatile modifier, double-checked locking implementation is broken.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16917/head:pull/16917
$ git checkout pull/16917
Update a local copy of the PR:
$ git checkout pull/16917
$ git pull https://git.openjdk.org/jdk.git pull/16917/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16917
View PR using the GUI difftool:
$ git pr show -t 16917
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16917.diff
Webrev
Link to Webrev Comment