Name: gm110360 Date: 08/07/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION : Windows NT Workstation 4.0
(Build 1381: Service Pack 6) with Service Pack 6a
A DESCRIPTION OF THE PROBLEM :
Documentation does not state that applet cannot call
getParameters() before init() is called. Calling init in
constructor will cause a NullPointerException in
Applet.java. The reason for failure is because Applet.java
requires the "stub" variable to be non-null before this
method is called. Instead this method (and numerous others)
should follow the code in isActive() in Applet.java.
Applets should *not* have to wrap the getParameter call in
a try...catch block.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a new applet by extenting javax.swing.JApplet.
2. In the applet's constructor, call getParameters
("SomeParam").
3. Compile and test the applet. It will *always* fail.
EXPECTED VERSUS ACTUAL BEHAVIOR :
Applet should not fail. getParameters should return null if
the "stub" variable is null.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
at java.applet.Applet.getParameter(Applet.java:158)
at TestingParamApplet.<init>(TestingParamApplet.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
orAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at java.lang.Class.newInstance0(Class.java:296)
at java.lang.Class.newInstance(Class.java:249)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:548)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:477)
at sun.applet.AppletPanel.run(AppletPanel.java:290)
at java.lang.Thread.run(Thread.java:536)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class TestingParamApplet extends javax.swing.JApplet {
public TestingParamApplet() {
String test = getParameter("TestParam");
}
public void init() {
this.text.setText(getParameter("TestParam"));
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
DO NOT call getParameter in your constructor. Either call
it in init or create a timer in your construtor that fires
every so often (maybe 50 milliseconds) and checks isActive
() before calling getParameter
(Review ID: 153926)
======================================================================