JDK-4144846 : Documentation for getCodeBase, getDocumentBase needs clarifying
  • Type: Enhancement
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.1.6,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1998-06-02
  • Updated: 2005-05-12
  • Resolved: 2005-05-12
Related Reports
Duplicate :  
Duplicate :  
Description

Name: jtC48319			Date: 06/02/98


In class Applet, both getCodeBase() and
getDocumentBase() only work after the init method
has been called. While this isn't a bug, the
documentation for these methods should say so. I
tried calling them in my constructor and couldn't
figure out why they weren't working.
(Review ID: 32851)
======================================================================

Comments
EVALUATION The following test and output from duplicate bug 4349585 illustrates this problem: import java.awt.*; import java.applet.*; import java.net.URL; public class Applet1 extends Applet { public Applet1() { System.out.println("Constructor here!"); URL codeBase; codeBase=getCodeBase(); } /* public void init() { System.out.println("Constructor here!"); URL codeBase; codeBase=getCodeBase(); } */ } java.lang.NullPointerException at java.applet.Applet.getCodeBase(Unknown Source) at Applet1.<init>(Applet1.java) at java.lang.Class.newInstance0(Native Method) at java.lang.Class.newInstance(Unknown Source) at sun.applet.AppletPanel.createApplet(Unknown Source) at sun.plugin.AppletViewer.createApplet(Unknown Source) at sun.applet.AppletPanel.runLoader(Unknown Source) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) iris.garcia@eng 2000-07-10 The standard practice for Applets is to not use a contstructor at all. This is due to the fact that the browser may not have established an environment for the Applet until well after the VM has constructed the Applet. As such any environmental related calls should be delayed until init(), not just the two mentioned in this report. I recommend that the documentation for the init() method be updated ###@###.### 2002-11-26 This is a duplicate of #4906095. ###@###.### 2005-05-12 06:34:09 GMT
26-11-2002