JDK-6534719 : Applets and AJAX don't mix in 1.5.0_11 in Internet Explorer, loaded twice
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2007-03-15
  • Updated: 2011-02-16
  • Resolved: 2007-04-05
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
JRE 1.5.0_11 is the only one affected.
  Older JREs from 1.5.0.x work fine and the 1.6.0 works OK too.

ADDITIONAL OS VERSION INFORMATION :
It's a Windows only problem, tested in Windows 2000, Windows XP using Internet Explorer. In Firefox it works OK.


A DESCRIPTION OF THE PROBLEM :
When an applet is being loaded from a html file using Internet Explorer with the JRE 1.5.0.11, it gets loaded twice. It needs a prepared page for it. Using simple html pages it works, but using something a bit more elaborated, using AJAX, makes it to fall into the problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Copy the following files in a web server docroot:

- works.html

<html>
<head>
<title>Normal Applet</title>
</head>

<body>
<h1>Normal Applet</h1>
<div id="applet"><applet height="60" alt="Browser has Java disabled" hspace="22" width="440" code="JavaVersionDisplayApplet.class">
</applet></div>
</body>
</html>


- bug.html

<html>
<head>
<title>AJAX Fetch Applet</title>

<script type="text/javascript">
function fetch_applet()
{
    var url = "applet.xml";
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {got_applet();};
        req.open("GET", url, true);
        req.send(null);
    }
    else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {got_applet();};
            req.open("GET", url, true);
            req.send();
        }
    }
}

function got_applet()
{
   var target = 'applet';
   // only if req is "loaded"
   if (req.readyState == 4) {
       // only if "OK"
       if (req.status == 200 || req.status == 304) {
           results = req.responseText;
       } else {
           results = "<p><b>System error loading applet:</b> <i>" + req.statusText + "</i></p>";
       }
       document.getElementById(target).innerHTML = results;
   }
}
</script>
</head>

<body onload="setTimeout('fetch_applet()',1000);">
<h1>AJAX Fetch Applet</h1>
<div id="applet"><b>Applet Goes Here</b></div>
</body>
</html>


- applet.xml

<applet height="60" alt="Browser has Java disabled" hspace="22" width="440" code="JavaVersionDisplayApplet.class">
</applet>


- The compiled class from JavaVersionDisplayApplet.java

import java.applet.Applet;
import java.awt.*;

public class JavaVersionDisplayApplet extends Applet
{

    public JavaVersionDisplayApplet()
    {
        Color color = Color.pink;
        setBackground(color);
        m_labVersionVendor = new Label(" Java Version: " + System.getProperty("java.version") + "  from " + System.getProperty("java.vendor"));
        add(m_labVersionVendor);
    }

    private Label m_labVersionVendor;
}


2) Open the java console and press 5 to increase the debug level

3) Now browse to .../javabug/works.html

4) Note what you see in the java console. The applet is loaded and executed only one time.

5) Shutdown IE and restart it. Again, open the java console and press 5.

6) Now browse to ../javabug/bug.html

7) Notice in the java console that the applet is loaded and started twice!.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The applet should be loaded and started only one time when using AJAX and Internet Explorer with the JRE 1.5.0.11

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION It looks it is caused by fix to 6489165 in 5.0u11 b03. The bug is no longer reproducilbe in the 5.0 update 12.
05-04-2007