RFR: 8159055: ImageIcon.setImage can't handle null parameter [v15]

Prasanta Sadhukhan psadhukhan at openjdk.org
Sun Jul 13 09:12:27 UTC 2025


> 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 `id` for that image and instantiates `MediaTracker` to associate the null image to that `id` and 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..

Prasanta Sadhukhan has updated the pull request incrementally with two additional commits since the last revision:

 - Document NPE behaviour and update test and add class-level statement
 - Document NPE behaviour and update test and add class-level statement

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/25767/files
  - new: https://git.openjdk.org/jdk/pull/25767/files/340254ec..dbf7edb0

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=25767&range=14
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=25767&range=13-14

  Stats: 187 lines in 2 files changed: 187 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/25767.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/25767/head:pull/25767

PR: https://git.openjdk.org/jdk/pull/25767


More information about the client-libs-dev mailing list