JDK-4710854 : JApplet.getCodeBase() and getDocumentBase() don't work as documented
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: pp_1.0,1.4.0,1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7,windows_2000
  • CPU: x86,sparc
  • Submitted: 2002-07-03
  • Updated: 2005-07-14
  • Resolved: 2005-07-14
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: gm110360			Date: 07/03/2002


FULL PRODUCT VERSION :
java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

FULL OPERATING SYSTEM VERSION : Win2kPro, all updates


EXTRA RELEVANT SYSTEM CONFIGURATION :
Latest docs and JDK

A DESCRIPTION OF THE PROBLEM :
getDocumentBase() returns an URL to the html file in which
the applet is embeded, not the parent dir of the html file.

Docs read-
getDocumentBase
public URL getDocumentBase()
Returns an absolute URL naming the directory of the
document in which the applet is embedded. For example,
suppose an applet is contained within the document:
    http://java.sun.com/products/jdk/1.2/index.html
 
The document base is:
    http://java.sun.com/products/jdk/1.2/
 

Returns-
the URL of the document that contains this applet.
see getCodeBase() also.

*********************************************************

getCodeBase() returns the parent of the html file the applet
is embedded in, not the URL of the applet itself.

Docs read:
public URL getCodeBase()
Gets the base URL. This is the URL of the applet itself.

Returns:
the URL of this applet.
See getDocumentBase() also


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.) make and applet, Mine just had:

public void init()
    {
    docBase = this.getDocumentBase();
    codeBase = this.getCodeBase();
    }
	
public void paint(Graphics g)
    {
    g.drawString(docBase.toString(), 25, 50);
    g.drawString(codeBase.toString(), 25, 100);
    }

2.) Make an html file with an <applet tag>
3.) Request it.


EXPECTED VERSUS ACTUAL BEHAVIOR :
expect: url to directory html file is in
expect: the url of the applet itself

actual: url to the html file
actual: url to the directory of the html file

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package chapter4;

import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;

public class JTMSplitPane extends JApplet
	{
	URL docBase;
	URL codeBase;
	
	public void init()
		{
		docBase = this.getDocumentBase();
		codeBase = this.getCodeBase();
						
		}
	
	public void paint(Graphics g)
		{
		g.drawString(docBase.toString(), 25, 50);
		g.drawString(codeBase.toString(), 25, 100);
		}

	}

***************************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>chapter4.JTMSplitPane</title></head><body>
<Applet code=chapter4.JTMSplitPane width=400 height=300></Applet>
</body></html>
---------- END SOURCE ----------
(Review ID: 153868) 
======================================================================

Comments
EVALUATION The applet spec is owned by plugin, so I'll reassign to that subcategory. ###@###.### 2002-07-07 This is the evaluation I got from java.sun.com: ============================================= public URL getDocumentBase() Returns an absolute URL naming the directory of the document in which the applet is embedded. For example, suppose an applet is contained within the document: http://java.sun.com/products/jdk/1.2/index.html The document base is: http://java.sun.com/products/jdk/1.2/ Returns: the URL of the document that contains this applet. ============================================== This description is copied directly from Applet.java file and sounds VERY contradictory. First it explains that it should return an "absolute URL naming the directory of the document in which the applet is embedded". After that it gives an example that cuts off the "index.html" part of the URL, and in conclusion it says that URL of the document that contains this applet should be returned. I looked through a bunch of books, and some documentation that is available online, as well as documentbase standard for the HTML. Conclusion: the very last line of the description is correct. This: =============================== The document base is: http://java.sun.com/products/jdk/1.2/ ================================= should not be mentioned at all. ******************************************************************* For the description of getCodeBase() I have to say that it is neither correct, nor complete. This is what it says in documentation at java.sun.com: ================================== public URL getCodeBase() Gets the base URL. This is the URL of the applet itself. Returns: the URL of this applet. =================================== While it should say that getCodeBase() returns the "codebase" parameter of the applet tag. Here is an example: <html><head><title>chapter4.JTMSplitPane</title></head><body> <Applet code=JTMSplitPane codebase="./source" width=600 height=300> </Applet></body></html> If this html is stored at http://java.sun.com/products/plugin/demos/demo.html, then the codebase should be http://java.sun.com/products/plugin/demos/source If we have the following html page: <html><head><title>chapter4.JTMSplitPane</title></head><body> <Applet code=JTMSplitPane width=600 height=300> </Applet></body></html> As you see this page does not mention "codebase" parameter at all. In this case getCodeBase should return the URL where the html document is residing. So, in case if we have http://java.sun.com/products/plugin/demos/demo.html, then codebase in this case would be http://java.sun.com/products/plugin/demos/ ***************************************************** Documentation for Applet.java should be changed for both getCodeBase() and getDocumentBase(). Current documentation is incorrect and confusing. It needs to be updated as soon as possible. If you have any questions, please feel free to contact me. ###@###.### 2002-07-15 This CR is fixed in most part by fixing 4456393. ###@###.### 2005-04-21 06:37:13 GMT The documentation has been cleaned up as part of 4456393. ###@###.### 2005-07-14 02:57:33 GMT
21-04-2005