JDK-4349585 : getCodeBase(), getDocumentBase() generate null pointer exception
  • Type: Bug
  • Component: tools
  • Sub-Component: appletviewer
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-06-29
  • Updated: 2000-07-10
  • Resolved: 2000-07-10
Related Reports
Duplicate :  
Description

Name: stC104175			Date: 06/29/2000


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)


Build an applet from the code below and use it in an HTML page.
Source Code:
-----------------------------------------
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();
	}
*/
}
-----------------------------------------
Error message/trace:
-----------------------------------------
Java(TM) Plug-in: Version 1.3.0-C
Using JRE version 1.3.0 Java HotSpot(TM) Client VM
  User home directory = C:\WINNT\Profiles\Armand

...

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)
-----------------------------------------
Other info:
-----------------------------------------
1.  To see the problem with 'getDocumentBase()', use it in the above code in
place of 'getCodeBase().'
2.  This is a condensation of the same problem that occurred to me while trying
to get Example 11-08 on page 604 of "Graphic Java 2" by David M. Geary,
published by Sun Microsystems Press, 1999, to work.
3.  I have found similar things in the bug database that were never confirmed.
4.  I have tried to find some documentation on the role of constructors in
Applets/JApplets to no avail.  It would be helpful to know where to find it.
-----------------------------------------

Thanks.
(Review ID: 106661) 
======================================================================

Comments
WORK AROUND Name: stC104175 Date: 06/29/2000 In the code shown above, use the problem routines in the init() method instead of in a constructor. ======================================================================
11-06-2004

EVALUATION Duplicate. iris.garcia@eng 2000-07-10
10-07-2000