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

Calls to Applet.getImage( URL ) fail to reflect changes in the URL's content.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 6
    • deploy
    • 6
    • 6
    • b92
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      1.6rc (build 87).

      ADDITIONAL OS VERSION INFORMATION :
      win_xp

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Tested with Internet Explorer 6.0 and 7.0

      A DESCRIPTION OF THE PROBLEM :
      The problem that we are encountering is that calls to Applet.getImage( URL ) are returning the same image data even though the image changes on the server for the same URL. For example, if we call:

      Image objImage1 = objApplet.getImage( new URL( “http://outserver/images/image.jpg” ) );

      // wait some time arbitrary about of time while the image on the
      // server changes. Then call get Image again.

      Image objImage2 = objApplet.getImage( new URL( “http://outserver/images/image.jpg” ) );

      The content of objImage1 is identical to objImage2 even though the contents have actually changed on the server. Eventually, if we keep calling getImage(…), it may or may not get the correct content.

      To work around this problem, we append a timestamp query string to the URL every time we try to load the image. This causes the url to change and should also causes the Applet.getImage( URL ) to load the image on every call.

      Below is the code that demonstrates exactly what we do when loading an image from within out Applet. This has been working from Java 1.3 to Java 1.6b2 build 85. It appears to be broken in Java 1.6b2 build 86 and 1.6rc (build 87).

      public Image loadImageWithTimestamp ( String pathToImage )
      {
          // get the images from the specified image folder on the web server

          // add an extra timestamp to the end of the query string to work around
          // bugs which seems to lose any GETs that are the same as previous gets

          // to work around a bug that won't send out a GET
          // per browser session where the query string is exactly the
          // same. Solution add timestamp to string
          Date now = new Date();
          String urlTimeStamp = now.toString();
          urlTimeStamp = urlTimeStamp.replace( ' ', '-' );
          urlTimeStamp = urlTimeStamp.replace( ':', '.' );

          urlTimeStamp = "?timestamp=" + urlTimeStamp;

          // An internal function that gets a reference to the current applet
          Applet applet = getFirstValidAppletContext();

          Image img = null;
          try
          {
              URL objPathToImage = new URL( m_hostBaseHttpAddressUrl, pathToImage + urlTimeStamp );
              img = applet.getImage( objPathToImage );
          }
          catch ( Exception objExcep )
          {
              System.err.println( "Failed to get image: ", objExcep );
          }
          return img;
      }

      REGRESSION. Last worked in version mustang

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Refer comments

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When the content of the destination page changes, the image displayed should change appropriately.
      ACTUAL -
      The image is the same although the content of the change has been modified at the server.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------


      public Image loadImageWithTimestamp ( String pathToImage )
      {
          // get the images from the specified image folder on the web server

          // add an extra timestamp to the end of the query string to work around
          // bugs which seems to lose any GETs that are the same as previous gets

          // to work around a bug that won't send out a GET
          // per browser session where the query string is exactly the
          // same. Solution add timestamp to string
          Date now = new Date();
          String urlTimeStamp = now.toString();
          urlTimeStamp = urlTimeStamp.replace( ' ', '-' );
          urlTimeStamp = urlTimeStamp.replace( ':', '.' );

          urlTimeStamp = "?timestamp=" + urlTimeStamp;

          // An internal function that gets a reference to the current applet
          Applet applet = getFirstValidAppletContext();

          Image img = null;
          try
          {
              URL objPathToImage = new URL( m_hostBaseHttpAddressUrl, pathToImage + urlTimeStamp );
              img = applet.getImage( objPathToImage );
          }
          catch ( Exception objExcep )
          {
              System.err.println( "Failed to get image: ", objExcep );
          }


          return img;
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None found.

      Release Regression From : mustang
      The above release value was the last known release where this
      bug was not reproducible. Since then there has been a regression.

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: