Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8040291

[macosx] Http-Images are not fully loaded when using ImageIcon

    Details

    • Subcomponent:
    • Resolved In Build:
      b22
    • CPU:
      x86
    • OS:
      os_x

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_20-ea"
        Java(TM) SE Runtime Environment (build 1.8.0_20-ea-b05)
        Java HotSpot(TM) 64-Bit Server VM (build 25.20-b05, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Darwin mankell 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

        A DESCRIPTION OF THE PROBLEM :
        Every now and then, MediaTracking of an ImageIcon does not seem to work all the way.

        The width reported by iconImage.getIconWidth() does not match the width reported by iconImage.getImage().getWidth(null).

        In earlier JDK versions, this did not occur.

        Here's what I expect:

        a call to:

        IconImage icon = new ImageIcon(someHttpURL);

        will load the image via HTTP and only return once the image has been completely loaded.
        When that happens, icon.getIconWidth() will return the image's width.
        It will be the same as icon.getImage().getWidth(null).

        This, I tested, is true for Java 1.8.0.


        This is what I observe:

        On 1.8.0u20, every now and then,
        icon.getIconWidth() returns -1, even though the URL is clearly valid.
        icon.getImage().getWidth(null) also return -1.

        However, after waiting a little while,
        icon.getIconWidth() still returns -1 and
        icon.getImage().getWidth(null) returns the true width

        So it seems to me, that the MediaTracker used in ImageIcon, does not wait until the image is fully loaded, in fact, it returns a status 10 (aborted).


        REGRESSION. Last worked in version 8

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b129)
        Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the provided class.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=113, image.width=113 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=130, image.width=130 imageLoadStatus=8
        iconWidth=159, image.width=159 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        Wait a little....
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=113, image.width=113
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=130, image.width=130
        iconWidth=159, image.width=159
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160

        ACTUAL -
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=113, image.width=113 imageLoadStatus=8
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        iconWidth=159, image.width=159 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=8
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=160, image.width=160 imageLoadStatus=10
        iconWidth=-1, image.width=-1 imageLoadStatus=10
        Wait a little....
        iconWidth=160, image.width=160
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=113, image.width=113
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=-1, image.width=160 ***** icon width is not correct *****
        iconWidth=160, image.width=160
        iconWidth=-1, image.width=130 ***** icon width is not correct *****
        iconWidth=159, image.width=159
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=160, image.width=160
        iconWidth=-1, image.width=160 ***** icon width is not correct *****

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import java.net.MalformedURLException;
        import java.net.URL;

        public class IconImageTest {
            public static void main(String[] args) throws MalformedURLException {

                final URL[] urls = new URL[70];

                urls[0] = new URL("http://ecx.images-amazon.com/images/I/414h77wL4EL._SL160_.jpg");
                urls[1] = new URL("http://ecx.images-amazon.com/images/I/515pogBxO9L._SL160_.jpg");
                urls[2] = new URL("http://ecx.images-amazon.com/images/I/41I1vwgqsXL._SL160_.jpg");
                urls[3] = new URL("http://ecx.images-amazon.com/images/I/51-JzKwWe-L._SL160_.jpg");
                urls[4] = new URL("http://ecx.images-amazon.com/images/I/51V5n3XX4sL._SL160_.jpg");
                urls[5] = new URL("http://ecx.images-amazon.com/images/I/610zMH8VYyL._SL160_.jpg");
                urls[6] = new URL("http://ecx.images-amazon.com/images/I/51pmAKfwTlL._SL160_.jpg");
                urls[7] = new URL("http://ecx.images-amazon.com/images/I/61vHzDEgxgL._SL160_.jpg");
                urls[8] = new URL("http://ecx.images-amazon.com/images/I/51TAPDNMBdL._SL160_.jpg");
                urls[9] = new URL("http://ecx.images-amazon.com/images/I/51ZuY7zfsfL._SL160_.jpg");
                urls[10] = new URL("http://ecx.images-amazon.com/images/I/41Upfpq4XnL._SL160_.jpg");
                urls[11] = new URL("http://ecx.images-amazon.com/images/I/51zSTVJM6nL._SL160_.jpg");
                urls[12] = new URL("http://ecx.images-amazon.com/images/I/51-6wmW4swL._SL160_.jpg");
                urls[13] = new URL("http://ecx.images-amazon.com/images/I/51gmuw5qUrL._SL160_.jpg");
                urls[14] = new URL("http://ecx.images-amazon.com/images/I/41NYyfjNZjL._SL160_.jpg");
                urls[15] = new URL("http://ecx.images-amazon.com/images/I/51RNerVHKRL._SL160_.jpg");
                urls[16] = new URL("http://ecx.images-amazon.com/images/I/51KpoPP738L._SL160_.jpg");
                urls[17] = new URL("http://ecx.images-amazon.com/images/I/61iKyNi5UKL._SL160_.jpg");
                urls[18] = new URL("http://ecx.images-amazon.com/images/I/61iGFtl2YmL._SL160_.jpg");
                urls[19] = new URL("http://ecx.images-amazon.com/images/I/41fos%2BEksdL._SL160_.jpg");
                urls[20] = new URL("http://ecx.images-amazon.com/images/I/51RpKf9APDL._SL160_.jpg");
                urls[21] = new URL("http://ecx.images-amazon.com/images/I/61e21Jz2yiL._SL160_.jpg");
                urls[22] = new URL("http://ecx.images-amazon.com/images/I/51AmYeBsMCL._SL160_.jpg");
                urls[23] = new URL("http://ecx.images-amazon.com/images/I/61aETwYg8PL._SL160_.jpg");
                urls[24] = new URL("http://ecx.images-amazon.com/images/I/61m5%2BVAZrrL._SL160_.jpg");
                urls[25] = new URL("http://ecx.images-amazon.com/images/I/51nA1JIuRNL._SL160_.jpg");
                urls[26] = new URL("http://ecx.images-amazon.com/images/I/41GRH80LYeL._SL160_.jpg");
                urls[27] = new URL("http://ecx.images-amazon.com/images/I/41IhcL9HZkL._SL160_.jpg");
                urls[28] = new URL("http://ecx.images-amazon.com/images/I/51k-Q52GnFL._SL160_.jpg");
                urls[29] = new URL("http://ecx.images-amazon.com/images/I/51SQ3BkujSL._SL160_.jpg");
                urls[30] = new URL("http://ecx.images-amazon.com/images/I/41iJNnii-ZL._SL160_.jpg");
                urls[31] = new URL("http://ecx.images-amazon.com/images/I/41etRDeiMoL._SL160_.jpg");
                urls[32] = new URL("http://ecx.images-amazon.com/images/I/51tr3o4kd9L._SL160_.jpg");
                urls[33] = new URL("http://ecx.images-amazon.com/images/I/5128-LvpmZL._SL160_.jpg");
                urls[34] = new URL("http://ecx.images-amazon.com/images/I/51leTIgrqWL._SL160_.jpg");
                urls[35] = new URL("http://ecx.images-amazon.com/images/I/41RpWVBJz6L._SL160_.jpg");
                urls[36] = new URL("http://ecx.images-amazon.com/images/I/51VjeYTFzOL._SL160_.jpg");
                urls[37] = new URL("http://ecx.images-amazon.com/images/I/61VQl%2B0YfQL._SL160_.jpg");
                urls[38] = new URL("http://ecx.images-amazon.com/images/I/41mJt4IVkhL._SL160_.jpg");
                urls[39] = new URL("http://ecx.images-amazon.com/images/I/417ZNQ5C1FL._SL160_.jpg");
                urls[40] = new URL("http://ecx.images-amazon.com/images/I/511zXx9fdCL._SL160_.jpg");
                urls[41] = new URL("http://ecx.images-amazon.com/images/I/61OycahzgyL._SL160_.jpg");
                urls[42] = new URL("http://ecx.images-amazon.com/images/I/51eCZAq37qL._SL160_.jpg");
                urls[43] = new URL("http://ecx.images-amazon.com/images/I/5113GxfgY3L._SL160_.jpg");
                urls[44] = new URL("http://ecx.images-amazon.com/images/I/61xnT6WcaEL._SL160_.jpg");
                urls[45] = new URL("http://ecx.images-amazon.com/images/I/51QWxgU9N2L._SL160_.jpg");
                urls[46] = new URL("http://ecx.images-amazon.com/images/I/5149PFGq8rL._SL160_.jpg");
                urls[47] = new URL("http://ecx.images-amazon.com/images/I/617W9ZTJGBL._SL160_.jpg");
                urls[48] = new URL("http://ecx.images-amazon.com/images/I/513JTvJWpFL._SL160_.jpg");
                urls[49] = new URL("http://ecx.images-amazon.com/images/I/6114I6QC7BL._SL160_.jpg");
                urls[50] = new URL("http://ecx.images-amazon.com/images/I/216QZM5FJ8L._SL160_.jpg");
                urls[51] = new URL("http://ecx.images-amazon.com/images/I/413WE38pDRL._SL160_.jpg");
                urls[52] = new URL("http://ecx.images-amazon.com/images/I/51LSN2zSeAL._SL160_.jpg");
                urls[53] = new URL("http://ecx.images-amazon.com/images/I/51PzHVqOMwL._SL160_.jpg");
                urls[54] = new URL("http://ecx.images-amazon.com/images/I/61GWhfvALPL._SL160_.jpg");
                urls[55] = new URL("http://ecx.images-amazon.com/images/I/41C5ZXEZwrL._SL160_.jpg");
                urls[56] = new URL("http://ecx.images-amazon.com/images/I/61teoR6B8JL._SL160_.jpg");
                urls[57] = new URL("http://ecx.images-amazon.com/images/I/51rnHibCn2L._SL160_.jpg");
                urls[58] = new URL("http://ecx.images-amazon.com/images/I/511aIQsGmhL._SL160_.jpg");
                urls[59] = new URL("http://ecx.images-amazon.com/images/I/51YgnRCFdOL._SL160_.jpg");
                urls[60] = new URL("http://ecx.images-amazon.com/images/I/51uAqL4pA4L._SL160_.jpg");
                urls[61] = new URL("http://ecx.images-amazon.com/images/I/514FnLMr5vL._SL160_.jpg");
                urls[62] = new URL("http://ecx.images-amazon.com/images/I/51NoPs4muzL._SL160_.jpg");
                urls[63] = new URL("http://ecx.images-amazon.com/images/I/515ndTGE9kL._SL160_.jpg");
                urls[64] = new URL("http://ecx.images-amazon.com/images/I/61XRtZ08c6L._SL160_.jpg");
                urls[65] = new URL("http://ecx.images-amazon.com/images/I/61kDVs82oRL._SL160_.jpg");
                urls[66] = new URL("http://ecx.images-amazon.com/images/I/61p85bjPV%2BL._SL160_.jpg");
                urls[67] = new URL("http://ecx.images-amazon.com/images/I/41JDQF9F5ML._SL160_.jpg");
                urls[68] = new URL("http://ecx.images-amazon.com/images/I/51ZqPCspJeL._SL160_.jpg");
                urls[69] = new URL("http://ecx.images-amazon.com/images/I/51cMFdhLFSL._SL160_.jpg");

                final ImageIcon[] icons = new ImageIcon[70];
                for (int i=0; i<urls.length; i++) {
                    icons[i] = new ImageIcon(urls[i]);
                    System.out.println("iconWidth=" + icons[i].getIconWidth() + ", image.width=" + icons[i].getImage().getWidth(null) + " imageLoadStatus=" + icons[i].getImageLoadStatus());
                    i++;
                }

                System.out.println("Wait a little....");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                for (int i=0; i<urls.length; i++) {
                    final int iconWidth = icons[i].getIconWidth();
                    final int width = icons[i].getImage().getWidth(null);
                    System.out.print("iconWidth=" + iconWidth + ", image.width=" + width);
                    if (iconWidth != width) System.out.println(" ***** icon width is not correct *****");
                    else System.out.println();
                    i++;
                }

            }
        }

        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alexsch Alexander Scherbatiy (Inactive)
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: