JDK-6776473 : JavaScript calling Java timing issue
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u10
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows,windows_xp
  • CPU: x86
  • Submitted: 2008-11-25
  • Updated: 2010-11-03
  • Resolved: 2009-05-20
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
6u14 b01Fixed
Related Reports
Duplicate :  
Relates :  
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
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.
25-11-2008

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>
25-11-2008