JDK-4070158 : (api) java.applet.Applet.getCodeBase() returns NullPointerException
  • Type: Bug
  • Component: tools
  • Sub-Component: appletviewer
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS:
    solaris_2.5.1,windows_nt,windows_2000 solaris_2.5.1,windows_nt,windows_2000
  • CPU: x86,sparc
  • Submitted: 1997-08-06
  • Updated: 2005-06-01
  • Resolved: 2005-06-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Relates :  
Description

Name: rlT66838			Date: 08/06/97


This is probably broken on every platform....

/*
java.applet.Applet.getCodeBase() returns NullPointerException
if the Applet is used as an application.

Compiling and running this program results in:

% javac AppletExample.java
% java AppletExample
java.lang.NullPointerException
        at java.applet.Applet.getCodeBase(Applet.java:110)
        at AppletExample.start(AppletExample.java:41)
        at AppletExample.main(AppletExample.java:48)

----------

Applet.java contains the following code at line 110:

    public URL getCodeBase() {
        return stub.getCodeBase();
    }

It needs to make sure "stub" isn't null. getCodeBase() should
return null if "stub" is null.

i.e.

    public URL getCodeBase() {
        return (stub == null ? null : stub.getCodeBase());
    }

Workaround? none

*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class AppletExample extends Applet {

    public void start() {
        if(getCodeBase() != null)
            showStatus(getCodeBase().toString());
    }

    public static void main(String[] args) {
        AppletExample ae = new AppletExample();
        ae.init();
        ae.start();
    }


}

company - Sun Microsystems , email - ###@###.###
======================================================================

Comments
EVALUATION Its a bug. --- jmelvin@east owns the api for java.applet. Routing to his team for evaluation. iris.garcia@eng 2001-04-09 Should try to fix this for Tiger. ###@###.### 2002-12-02 It is not a bug. Applet cannot return code base if it does not have an AppletStub. Only AppletStub has information about code base. So you should imlement your own AppletStub and set it for your Applet. For this a special method Applet.setStub(AppletStub stub) exists. ###@###.### 2005-06-01 13:07:16 GMT
01-06-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mustang
17-09-2004

WORK AROUND Name: rlT66838 Date: 08/06/97 ======================================================================
17-09-2004