JDK-4906095 : Document restriction of java.applet.Applet constructor
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.1.6,1.3.0,1.4.1,1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_95,windows_nt,windows_2000
  • CPU: x86
  • Submitted: 2003-08-13
  • Updated: 2017-05-19
  • Resolved: 2005-03-16
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
6 b28Fixed
Related Reports
Duplicate :  
Duplicate :  
Description
Name: gm110360			Date: 08/13/2003


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

FULL OS VERSION :
Windows 2000

A DESCRIPTION OF THE PROBLEM :
I am calling getParameter() from JApplet and I am getting the following error message:
"java.lang.NullPointerException at java.applet.Applet.getParameter(Applet.java:158)"


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile BadApplet, create jar file, put jar into web directory. Open html file page (i have tried 1.3, 1.4, html below as well as html generated with htmlconverter.exe (second below) nothing works):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Alpha Gen US GUI</title>
</head>
<BODY BGCOLOR="#CCCCCC">
<FONT COLOR="#808080">
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" WIDTH = 1000 HEIGHT = 750>
<NOEMBED>
<XMP>
<APPLET CODE = "BadApplet.class" ARCHIVE="test.jar" WIDTH = 1000 HEIGHT = 750>
</xmp>
<param>
<param>
<param>
<param>
<param>
</applet>
</noembed>
</object>
</body>
</html>



//++++++++++++++ Generated by HTML Converter ++++++++++++++++++++++++

<html>
<head>
<title>Alpha</title>
</head>
<body>
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<object>
    <param>
    <param>
    <param>
    <param>
    <param>
    <param>

    <COMMENT>
	<embed>
	    <noembed>
            
            </noembed>
	</embed>
    </COMMENT>
</object>

<!--
<APPLET CODE = "BadApplet.class" ARCHIVE = "test.jar" WIDTH = 1000 HEIGHT = 750>
<PARAM NAME = "HOST" VALUE = "caldtd524564" >
<PARAM NAME = "PORT" VALUE = "10011" >


</APPLET>
-->


<!--"END_CONVERTED_APPLET"-->

</body>
</html>



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
applet started
ACTUAL -
applet initialization failed

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
	at java.applet.Applet.getParameter(Applet.java:158)
	at BadApplet.initLogin(BadApplet.java:28)
	at BadApplet.<init>(BadApplet.java:21)
	at BadApplet.<init>(BadApplet.java:16)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
	at java.lang.Class.newInstance0(Class.java:306)
	at java.lang.Class.newInstance(Class.java:259)
	at sun.applet.AppletPanel.createApplet(AppletPanel.java:566)
	at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1775)
	at sun.applet.AppletPanel.runLoader(AppletPanel.java:495)
	at sun.applet.AppletPanel.run(AppletPanel.java:292)
	at java.lang.Thread.run(Thread.java:536)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.rmi.*;
import java.rmi.server.*;
import java.util.*;
import java.text.*;
import javax.swing.table.*;
import javax.swing.border.*;

public class BadApplet
extends javax.swing.JApplet
{
  public BadApplet() {
    this(true);
  }

  public BadApplet(boolean inApplet) {
    inAnApplet = inApplet;
    initLogin();
  }


  protected void initLogin()
  {
    System.out.println("before getParameter()");
    String host = getParameter("HOST");
    System.out.println("host = " + host);
  }

  protected boolean inAnApplet = true;

}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
If I hardcode the parameters (do not call getParameter() at all) everything works fine
(Incident Review ID: 189273) 
======================================================================
###@###.### 2003-08-14

Comments
EVALUATION Judging from the stack trace, they are using plugin. There doesn't really seem to be any use of Swing or AWT, so I'm going to guess that applet_spec is the most appropriate category. ###@###.### 2003-08-13 ============================================================================ (More evaluation, by ###@###.### 2003-08-13) Hello, After investigation, I found that, problem is neither with Java Plugin nor with Applet.getParameter(). Rather, it's because the submitter of this problem has used getParameter() in his applet at inappropriate time before the Applet was loaded into memory. --- Excerpt from original BadApplet.java (notice that getParameter was called in the constructor of BadApplet): ..... public BadApplet(boolean inApplet) { inAnApplet = inApplet; initLogin(); } protected void initLogin() { System.out.println("before getParameter()"); String host = getParameter("HOST"); System.out.println("host = " + host); } ---- End of excerpt --------------------- Now, if BadApplet.java is changed to as follow, getParameter() will work fine: ---- Excerpt of new BadApplet.java, where getParameter() is called in override init(): public BadApplet(boolean inApplet) { inAnApplet = inApplet; } public void init() { System.out.println("before getParameter()"); String host = getParameter("HOST"); System.out.println("host = " + host); } ------ End of excerpt ---------------------------------- In the life cycle of an applet, during applet loading, we see: (step1) instance of Applet class created (step 2) the applet is loaded into memory and initializes itself (step 3) applet start running. Only during (step 2), an AppletStub would be attached to the Applet using Applet.setStub(). This stub serves as the interface between the applet and the browser or applet viewer environment, and is responsible to deliver applet information to request like getParameter(). In my modified BadApplet, getParameter() is called during init(). init() is called everytime the applet is loaded or reloaded into memory --> (step2). In submitter's applet code, getParameter() is used in (step 1)! Though naive as it may seem, when searching google on java forum, I realized many java coders had ran into the same problem as submitter. I think the problem is either: (A) There isn't any good documentation to suggest when is appropriate for Applet.getParameter() to be used (with respect to Applet loading mechanism). or (B) AppletStub should be set at instantation of Applet object (step 1). Can this be done? Though Applet.setStub() does not belong to Java 2 specs, it's a public method open to anyone who knows of its existance. Searching for usage of Applet.setStub(), I found: com.sun.jnlp.AppletContainer java.beans.AppletInitializer java.beans.Beans sun.applet.AppletPanel. In fact, the reported problem can be seen by using sun.applet.AppletViewer to view submitter's original applet. So in order to discuss solution (B), participation from JavaWS, AWT, Beans teams will be needed. ###@###.### 2003-08-14 ========================================================================================= As per investigation, this is clearly not a plugin or ws bug. I will reassign this bug over to AWT. If participation from deployment team is needed when discussing solution (B), please contact us at ###@###.###. ###@###.### 2003-08-29 As per the investigation above, this is clearly not a bug in AWT. As I reminded ###@###.### and the deployment earlier, this is precisely the kind of bug that the java_plugin/applet_spec subcategory was created for. ###@###.### agreed to be the responsible manager of such bugs, and in fact, he specifically requested that they belong to the plugin team. ###@###.### 2003-08-29 This is an applet spec bug. I will reassign it to myself to handle the spec changes in CCC. ###@###.### 2004-07-23 Applet is not initialized until Applet.init() is called. Thus, when the applet is constructed, the applet should avoid calling into other java.applet.Applet methods because it has not been fully initialized. ###@###.### 2005-2-10 06:16:59 GMT
10-02-2005