|
Quick Lists
|
|
Bug ID:
|
4274668
|
|
Votes
|
3
|
|
Synopsis
|
getCodeBase() should return a JAR URL if the applet's class file is in a JAR
|
|
Category
|
java:appletviewer
|
|
Reported Against
|
kestrel
|
|
Release Fixed
|
|
|
State
|
6-Fix Understood,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
4456393
,
4214785
|
|
Submit Date
|
22-SEP-1999
|
|
Description
|
Though not entirely clear from the spec for Applet.getCodeBase() and
AppletContext.getCodeBase(), it seems reasonable to assume that if the class
file for an applet is within a JAR file, then the returned code base should
reference that location. Currently it does not.
FILE: GetCodeBase.java
import java.applet.Applet;
public class GetCodeBase extends Applet {
public void init() {
System.out.println("getCodeBase() = " + getCodeBase());
}
}
FILE: GetCodeBase.html
<html>
<body>
<applet width=100 height=100 code=GetCodeBase.class archive=GetCodeBase.jar>
</applet>
</body>
</html>
OUTPUT:
( xxxxx@xxxxx ) $ java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-G)
Java HotSpot (TM) Client VM (build 1.3-G, interpreted mode)
( xxxxx@xxxxx ) $ javac GetCodeBase.java
( xxxxx@xxxxx ) $ jar cf GetCodeBase.jar GetCodeBase.class
( xxxxx@xxxxx ) $ rm GetCodeBase.class
( xxxxx@xxxxx ) $ appletviewer GetCodeBase.html
getCodeBase() = file:/home/iag/work/bug/av/
xxxxx@xxxxx 1999-09-22
|
|
Work Around
|
N/A
|
|
Evaluation
|
JAR URLs were introduced in JDK1.2 this unexpected behaviour is probably an
oversight.
This problem arises due to a lack of clarity in the spec. To fully address this
problem, The API for Applet.getCodeBase() and AppletContext.getCodeBase()
should be extended to include examples of the expected return value for cases
where the .class file does and does not reside in a JAR file. Intended use and
past behaviour in AppletViewer and Plug-in should be considered.
It seems reasonable to assume that getCodeBase() should return a JAR URL if
the applet class file is contained within a JAR. A benefit of this
interpretation is that getCodeBase() could be used in construting valid URLs
for locating images and audio clips within the JAR. (See bug 4214785).
In AppletViewer, composition of the return value for getCodeBase() is localized
to the constructor for sun.applet.AppletViewerPanel (AVPanel). Currently the
AVPanel is immutable and is created before the location of the applet's
classfile is known.
Changing this behaviour is potentially risky because of unknown dependencies on
the currently stored value. For instance, the constructor for AppletClassLoader
takes a single parameter, the "applet code base URL". This URL is used by
AppletClassLoader.findClass() as the second search location when the class file
is not found in they loaded JARs. Perhaps what should be used in this case is
the value returned by Applet.getDocumentBase()? In any event, careful testing
should be done when this problem is fixed.
xxxxx@xxxxx 1999-09-22
I agree that the javadoc for Applet.getCodeBase() is inadequate and
needs to be updated. This method should return the URL from the
codebase field within the applet tag of an html page. If that field
is not present then the URL of the document is the codebase.
This is a distinct concept from the jar file which contains the
main applet class. The codebase is the base URL which the various
jars from the archive field in the applet tag are resolved relative to.
It is also the place of last resort where individual .class files are
loaded from if they are not present in any jar archives. It would be
inconsistent with past behavior and "wrong" to have getCodeBase() return
the jar: URL of the jar file containing the main applet class.
I would suggest closing this as "not a bug". The javadoc for getCodeBase()
should probably be improved but perhaps under a different bugid.
xxxxx@xxxxx 2001-03-23
|
|
Comments
|
Submitted On 03-MAY-2000
kriff
I disagree. Modifying the semantics of getCodeBase() now is just asking for trouble. People need to get
used to the idea of using Class.getResource(..) for locating images, and other files within an applet's jar file.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |