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

[Mac, Retina] StringIndexOutOfBoundsException with image urls without extension

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8u20
    • 8
    • javafx
    • None
    • OSX Retina

    Description

      Custom URLS where one reference an image without an extension throw (usually silently) an exception and refuses to load the image at all.

      Given an URL (for testing) like file:1234532 the following exception is thrown:

      java.lang.StringIndexOutOfBoundsException: String index out of range: -1
      at java.lang.String.substring(String.java:1954)
      at com.sun.javafx.iio.ImageStorage.loadAll(ImageStorage.java:304)
      at com.sun.javafx.tk.quantum.PrismImageLoader2.loadAll(PrismImageLoader2.java:119)
      at com.sun.javafx.tk.quantum.PrismImageLoader2.<init>(PrismImageLoader2.java:70)
      at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:668)
      at javafx.scene.image.Image.loadImage(Image.java:1041)
      at javafx.scene.image.Image.initialize(Image.java:785)
      at javafx.scene.image.Image.<init>(Image.java:599)
      at CustomImageResourceLoader.start(CustomImageResourceLoader.java:19)

      I caught this bug because I do have a custom URLConnectionHandler called "pmd" and I access remote images just by a magic id. So, the URL looks like pmd:7473838 - this works perfectly in WebView, but not with fx.Image.

      The problematic code is located in com.sun.javafx.iio.ImageStorage where the system tries to find the extension part of the image filename and tries to append the @2x for retina images.
      The method used is semi-perfect I think, because it will also fail to find the right position if the url looks like

      http://my.pic.server.net/image.jpg?param=234.123

      I do not know what was the aim to try to find retina images in the ImageStorage class, but I guess it is just wrong to try to load each and every picture using the retina filename first.

      I will prepare a patch if you guide me the direction you want this to be fixed.


      Quick Workaround: add a dummy extension to your url like:
      pmd:17356463#.jpg

      Attachments

        Issue Links

          Activity

            People

              flar Jim Graham
              mivankovijfx Mario Ivankovits (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: