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

SplashScreen.setImageURL(URL imageURL) throws ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0-beta2"
      Java(TM) SE Runtime Environment (build 1.6.0-beta2-b86)
      Java HotSpot(TM) Client VM (build 1.6.0-beta2-b86, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      java.awt.SplashScreen.setImageURL(URL imageURL) may throw a ArrayIndexOutOfBoundsException with many custom Types of URLs.

      Internal, this method copy the bytes from the urlStream in a new buffer of size 'length'. The buffer may grow during the copying (if needed).

      But the variable 'length'. is initialized as follows:
      >>>
              URLConnection connection = imageURL.openConnection();
              connection.connect();
              int length = connection.getContentLength();
              java.io.InputStream stream = connection.getInputStream();
              byte[] buf = new byte[length];
      <<<

      Ant this is a bug: The Javadoc API says that URLConnection.getContentLength() may return "-1 if the content length is not known." In fact, this is the StandardImplementation of java.net.URLConnection.getContentLength(), so SplashScreen.setImageURL(URL imageURL) may throw a ArrayIndexOutOfBoundsException beacuse the inital length is -1.

      This bug can be easily fixed by adding a new line Of code:
      >>>
              URLConnection connection = imageURL.openConnection();
              connection.connect();
              int length = connection.getContentLength();
      >>>>>> length = (length < 0) ? 1 : length;
              java.io.InputStream stream = connection.getInputStream();
              byte[] buf = new byte[length];
      <<<

      Or maybe one should choose a bigger inital length for unknown content, for example 1024.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      see Description

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: