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

(api) getDocumentBase and getCodeBase do each other's jobs.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: pp_1.0, 1.2.1, 1.3.0, 1.3.1, 1.3.1_03, 1.4.0, 1.4.1
    • Fix Version/s: 1.4.2
    • Component/s: docs
    • Subcomponent:
    • Resolved In Build:
      b14
    • CPU:
      generic, x86, sparc
    • OS:
      generic, solaris_7, solaris_8, windows_nt, windows_2000

      Description

      According to the 1.3 API doc, getDocumentBase() is supposed to
      return the URL of the directory of the document in which an applet
      is embedded. According to the 1.3 API doc, getCodeBase is supposed
      to return the URL of the applet itself. The actual behavior is
      reversed and has been reversed for a long time.

      algol% cat SimpleApplet.java
      import java.applet.Applet;
      import java.awt.Graphics;
      import java.awt.Color;
      public class SimpleApplet extends Applet{
        public void init() {
           setBackground(Color.cyan);
        }
        public void start() {
           System.out.println("starting...");
        }
        public void stop() {
           System.out.println("stopping...");
        }
        public void destroy() {
           System.out.println("preparing to unload...");
        }
        public void paint(Graphics g){
           System.out.println("Paint");
           g.setColor(Color.blue);
           g.drawRect(0, 0, getSize().width -1, getSize().height -1);
           g.setColor(Color.red);
           g.drawString("getDocumentBase: "+getDocumentBase(), 15, 25);
           g.drawString("getCodeBase: "+getCodeBase(), 15, 35);
        }
      }

      algol% cat SimpleApplet.html
      <HTML>
      <BODY>
      <APPLET CODE=SimpleApplet.class WIDTH=200 HEIGHT=100>
      </APPLET>
      </BODY>
      </HTML>

      I tested a large number of JDKs and found that the results have been stable
      for a long time (at least on Solaris/sparc):

      getDocumentBase file:/home/ajacobs/public_html/BasicJava1/SimpleApplet.html
      getCodeBase file:/home/ajacobs/public_html/BasicJava1/

      The JDKs checked: 1.1.6, 1.1.7, 1.1.8_13, 1.2 FCS, 1.2.1_004, 1.2.2_008,
      1.2.2_08, 1.3.1, and 1.4.

      Testing on Merlin (1.4) shows that behavior is consistent on Windows and
      Intel/Solaris.

      According to the JDK 1.3 API documentation, the results should have been

      getCodeBase file:/home/ajacobs/public_html/BasicJava1/SimpleApplet.html
      getDocumentBase file:/home/ajacobs/public_html/BasicJava1/


      allan.jacobs@Eng 2001-05-09

      Name: jk109818 Date: 11/05/2001


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      In the API, getDocumentBase() is listed as "Return(ing) an absolute URL naming
      the directory of the document in which the applet is embedded." However
      getDocumentBase(), when a toString() is used prints "the URL of the applet
      itself" -- the function listed for getCodeBase(). A Simalar screen print of the
      toString() of getCodeBase() displays the base directory of the applet.

      Please contact me if I have misinterpreted the API.
      I have found this discrepancy on VM's 1.3.1 and 1.3.0.
      (Review ID: 134789)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shommel Scott Hommel (Inactive)
              Reporter:
              ajacobssunw Allan Jacobs (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: