javax.swing.ImageIcon constructor doesn't handle null input gracefully. Instead, a NullPointerException is thrown, and execution hangs. For example, with 7u25: Uncaught error fetching image: java.lang.NullPointerException at java.io.FileInputStream.<init>(FileInputStream.java:134) at java.io.FileInputStream.<init>(FileInputStream.java:97) at sun.awt.image.FileImageSource.getDecoder(FileImageSource.java:53) at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:263) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:205) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169) Taking a thread dump then reveals that the main thread has gone into an Object.wait(), and it will remain there forever because the "Image Fetcher 0" thread failed to fetch an image: "Image Fetcher 0" daemon prio=8 tid=0x046e4000 nid=0x7964 in Object.wait() [0x0520f000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x0f0b06e0> (a java.util.Vector) at sun.awt.image.ImageFetcher.nextImage(ImageFetcher.java:147) - locked <0x0f0b06e0> (a java.util.Vector) at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:200) at sun.awt.image.ImageFetcher.run(ImageFetcher.java:169) "main" prio=6 tid=0x0223bc00 nid=0x8784 in Object.wait() [0x0238f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x0f0afe38> (a java.awt.MediaTracker) at java.awt.MediaTracker.waitForID(MediaTracker.java:667) - locked <0x0f0afe38> (a java.awt.MediaTracker) at javax.swing.ImageIcon.loadImage(ImageIcon.java:302) - locked <0x0f0afe38> (a java.awt.MediaTracker) at javax.swing.ImageIcon.<init>(ImageIcon.java:153) at javax.swing.ImageIcon.<init>(ImageIcon.java:174) at TestImageIcon.main(TestImageIcon.java:3) TestCase: public class TestImageIcon { public static void main (String args[]) throws Exception{ javax.swing.ImageIcon ic = new javax.swing.ImageIcon((String)null); } }
|