United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6776473 JavaScript calling Java timing issue
JDK-6776473 : JavaScript calling Java timing issue

Details
Type:
Bug
Submit Date:
2008-11-25
Status:
Closed
Updated Date:
2010-11-03
Project Name:
JDK
Resolved Date:
2009-05-20
Component:
deploy
OS:
windows_xp,windows
Sub-Component:
plugin
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u10
Fixed Versions:
6u14 (b01)

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
The following sample demonstrates a problem of JavaScript calling Java. This issue is only reproducible with New Java Plug-In. It is not reproducible with Classic Java Plug-In in 6u10.

Env:
6u10, XP, IE.

<applet code>
import javax.swing.JApplet;
public class SimpleApplet extends JApplet {
private static final long serialVersionUID = -681454679772431812L;
/** Initializes the applet GOSEApplet */
public void init() {
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
System.out.println("SimpleApplet.init()");
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}

public void start() {
System.out.println("SimpleApplet.start()");
}

public void stop() {
System.out.println("SimpleApplet.stop()");
}


public void destroy() {
System.out.println("SimpleApplet.destroy()");
}

/*
* Meant to be called by JavaScript on HTML page
*/
public void echoPrint(String message) {
System.out.println("In SimpleApplet.echoPrint(): "+message);
}
}
</applet code>

And here is the HTML page:
<HTML>
<HEAD>
<TITLE> SimpleApplet </TITLE>
</HEAD>
<BODY>

<OBJECT name="simpleApplet" classid="clsid:CAFEEFAC-0015-0000-FFFF-ABCDEFFEDCBA" width="1" height="1">
<PARAM name="name" value="simpleApplet">
<PARAM name="code" value="SimpleApplet.class">
<PARAM name="archive" value="SimpleApplet.jar">
<PARAM name="codebase" value="applets">
</OBJECT>

<script type="text/javascript">
document.simpleApplet.echoPrint("TEST1");
</script>
</BODY>
</HTML>


Expected Output:
SimpleApplet.init()
SimpleApplet.start()
In SimpleApplet.echoPrint(): TEST1

                                    

Comments
WORK AROUND

<HTML>
<HEAD>
<TITLE> SimpleApplet </TITLE>
</HEAD>
<BODY onload="testJSCall()">
 
<OBJECT name="simpleApplet" classid="clsid:CAFEEFAC-0015-0000-FFFF-ABCDEFFEDCBA" width="1" height="1">
<PARAM name="name" value="simpleApplet">
<PARAM name="code" value="SimpleApplet.class">
<PARAM name="archive" value="SimpleApplet.jar">
<PARAM name="codebase" value="applets">
</OBJECT>
 
<script type="text/javascript">
function testJSCall() {
   document.simpleApplet.echoPrint("TEST1");
}
</script>
</BODY>
</HTML>
                                     
2008-11-25
EVALUATION

In the new plugin, javascript to java call is allowed after the applet's init() is completed. In the old plugin, js->java call is allowd after the applet's start() is completed. 

The new plugin need follow the existing behavior in the old plugin.

In the plugin, we remove this js->java barrier if applet start a java->js call (at the earliest possible time in init()). Unlike the old plugin, all js->java calls are allowed after the barrier is removed. The new plugin does not differentiate if a js->java call is a part of java->js->java roundtrip.
                                     
2008-11-25



Hardware and Software, Engineered to Work Together