-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8159055: Clarify handling of null and invalid image data for ImageIcon constructors and setImage method #25767
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 |
|
@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 1099 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
|
|
Does it require to update the doc as well to explicitly mention about NULL parameter ? |
|
I feel it's better to inform the user in the spec otherwise application may not know what will be done with NULL image |
CSR needed ? |
|
yes..i will raise it once we are done with this PR approval.. |
Ok... |
No, as I mentioned in the description the MediaTracker creation and id addition, tracking and removal is supposedly not required for null image. |
kumarabhi006
left a comment
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.
LGTM
azuev-java
left a comment
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.
Looks good.
|
Raised CSR https://bugs.openjdk.org/browse/JDK-8359398 |
aivanov-jdk
left a comment
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.
The ImageIcon constructor that accepts Image has the same problem, or a similar problem.
jdk/src/java.desktop/share/classes/javax/swing/ImageIcon.java
Lines 224 to 226 in 9d06057
| public ImageIcon (Image image) { | |
| this.image = image; | |
| Object o = image.getProperty("comment", imageObserver); |
It throws NullPointerException if a null parameter is passed. Other constructors handle null values, so you should unify handling of null images.
I agree. Not saying how null is handled is a bug. So fixing it is a bug fix, not an enhancement. |
| new ImageIcon((URL)null); | ||
| } else if (v == ArgVal.INVALID_DATA) { | ||
| expected = false; | ||
| new ImageIcon("file://" + imgName, "gif"); |
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.
There's a discrepancy: null is tested with one-arg constructor whereas invalid data is tested with two-arg constructor which accepts the description in addition to the URL.
More over, new ImageIcon("file://" + imgName, "gif") does not call ImageIcon(URL, String) constructor, it calls ImageIcon(String, String).
| new ImageIcon(bytes); | ||
| } else if (v == ArgVal.INVALID_DATA) { | ||
| expected = false; | ||
| new ImageIcon(new byte[0], "gif"); |
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.
Why not new ImageIcon(new byte[0])?
Why is it new byte[0] instead of invalidData that you seemingly created for the purpose of having invalid data?
| break; | ||
| case IMAGE : | ||
| if (v == ArgVal.NULL) { | ||
| new ImageIcon((Image)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.
| new ImageIcon((Image)null); | |
| new ImageIcon((Image) null); |
I guess you advocated for having a space between the type cast operator and its argument.
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.
Personally, I do not like having a space there.
| if (expected && !passed) { | ||
| System.err.println("Did not receive expected exception for : " + a); | ||
| throw new RuntimeException("Test failed"); | ||
| } |
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.
| if (expected && !passed) { | |
| System.err.println("Did not receive expected exception for : " + a); | |
| throw new RuntimeException("Test failed"); | |
| } | |
| if (expected && !passed) { | |
| throw new RuntimeException("Did not receive expected exception for: " + a); | |
| } |
Why not throw a detailed error message, this would make analysing test failure easier. At the very least, you will be able to distinguish different types of failures without looking into the test log file.
| if (!expected && !passed) { | ||
| System.err.println("Received unexpected exception for : " + a); | ||
| throw new RuntimeException("Test failed"); | ||
| } |
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.
| if (!expected && !passed) { | |
| System.err.println("Received unexpected exception for : " + a); | |
| throw new RuntimeException("Test failed"); | |
| } | |
| if (!expected && !passed) { | |
| throw new RuntimeException("Received unexpected exception for: " + a); | |
| } |
|
This PR seems to be back waiting on the CSR ? |
Yes, because the text was updated. Additionally, the test needs updating because it doesn't test ImageIcon(URL) constructor, it tests jdk/test/jdk/javax/swing/ImageIcon/ImageIconTest.java Lines 69 to 76 in c6be2a9
|
|
Test updated |
aivanov-jdk
left a comment
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.
Looks good… except for lots of unexpected blank lines in the test code.
| switch (a) { | ||
|
|
||
| case FILE : | ||
|
|
||
| expected = false; | ||
| String s = (v == ArgVal.NULL) ? null : imgName; | ||
| new ImageIcon(s); | ||
| passed = true; // no exception expected for this case | ||
| break; | ||
|
|
||
| case URL : |
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.
Was adding so many blank lines intentional?
|
Don't you want to use JUnit for I think using separate small methods to test I posted /*
* @test
* @summary Verifies behavior of ImageIcon constructors with null parameters
* @run junit ImageIconConstructorsTest
*/
public final class ImageIconConstructorsTest {
}You'll have to add test methods for invalid files and invalid data, though. The jtreg report looks like this: |
| break; | ||
| case IMAGE : | ||
| if (v == ArgVal.NULL) { | ||
| new ImageIcon((Image)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.
Personally, I do not like having a space there.
|
/touch |
|
@prsadhuk The pull request is being re-evaluated and the inactivity timeout has been reset. |
|
/integrate |
|
Going to push as commit 98e64cf.
Your commit was automatically rebased without conflicts. |
Neither do I. There should be no space between a |
When trying to call 'icon.setImage(null);' where 'icon' is an instance of ImageIcon, a null pointer exception is thrown at runtime.
The code tried to get the
idfor that image and instantiatesMediaTrackerto associate the null image to thatidand checks the status of loading this null image, removes the null image from the tracker and then tries to get the image width where it throws NPE as image is null.It's better to not go through all MediaTracker usage and bail out initially itself for null image..
Progress
Issues
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25767/head:pull/25767$ git checkout pull/25767Update a local copy of the PR:
$ git checkout pull/25767$ git pull https://git.openjdk.org/jdk.git pull/25767/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25767View PR using the GUI difftool:
$ git pr show -t 25767Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25767.diff
Using Webrev
Link to Webrev Comment