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

dtjava.js does not support asynchronous script loading

XMLWordPrintable

      FULL PRODUCT VERSION :
      8u60

      A DESCRIPTION OF THE PROBLEM :
      The following code in dtjava.js is used to define the location of the code base:

          var jscodebase = (function () {
              // <script> elements are added to the DOM and run synchronously,
              // the currently running script will also be the last element in the array
              var scripts = document.getElementsByTagName("script");
              var src = scripts[scripts.length - 1].getAttribute("src");
              return src.substring(0, src.lastIndexOf('/') + 1);
          })();

      When scripts are loaded asynchronously, the assumption that dtjava.js will be the last element in scripts is not generally met.

      In cases where scripts[scripts.length - 1].getAttribute("src") returns null, this throws an error.

      In other cases, the returned value will not generally describe the location of dtjava.js.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The code should return the base for the location of dtjava,js.


      ACTUAL -
      With asynchronous script loading:
      1. The code fails with an error for if scripts[length-1] has no src attribute.
      2. In other cases, the returned code base will not generally be correct. As a result, dtjava.js will generate 404s when attempting to load images such as error.png.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Likely to occur in any web page using dtjava.js with asynchronous script loading.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Simply iterating over the scripts list in the function to fine dtjava.js instead of assuming it is the last script in the list would fix this issue.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: