JDK-6204697 : Calling an applet method from a Html file in the IE Java plug-in
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.beans
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-12-06
  • Updated: 2011-01-19
  • Resolved: 2006-11-19
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)
and
java version "1.4.2_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP
Version 2002
Service pack 1
IE 6.0.2800

EXTRA RELEVANT SYSTEM CONFIGURATION :
Pentium P4m 1.9Ghz
512 Ram

A DESCRIPTION OF THE PROBLEM :
I'm working on some Sun API (XMLEncoder) to obtain a Swing applet, and add some code for understanding the XMLEncoder.
The calling method works fine when I call the method getDocument() direct from the applet, from the getDocument() applet button.
But something goes wrong with writeObject when I call the method getDocument() from the html file?
I think that this must be some bug with the Java Plug-in in IE because with Nescape or with Mozilla using 1.4.2_04 there is no problem...

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Some people and me write a simple applet to show the problem...to see step-by-step the bug process.
1) Work great in IE:
key pressed the applet's button "GET", calling the applet method:

2) works for the html button: "String 22", calling the method
--> public String getDocument(String obj)

3) bug for the html button: "Integer 22 passed by script", calling the method:
--> public String getDocument(Integer obj) (this is the same method that works great from an direct calling from the applet button "GET")

3) bug for the html button: "Integer 22 hardcoded in applet", calling the method:
-->  public String getDocument()


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would like the same result for all calling situations:
A right Object xml encoding:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
 <string>22</string>
</java>
ACTUAL -
Results for case:
1) String getDocument(Integer obj)
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
 <int>22</int>
</java>

2) <?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
 <string>22</string>
</java>

3) ERROR BUG!!!!!!!!! Nothing is encode
String getDocument(Integer obj)
java.lang.NullPointerException
Continuing ...
java.lang.Exception: discarding statement XMLEncoder0.writeObject(Integer0);
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
</java>

4) ERROR BUG!!!!!!!!! Nothing is encode
ava.lang.NullPointerException
Continuing ...
java.lang.Exception: discarding statement XMLEncoder0.writeObject(Integer0);
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
</java>

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Results for case:
I would like the same result as the 1) & 2) but:

3) ERROR BUG!!!!!!!!! Nothing is encode
String getDocument(Integer obj)
java.lang.NullPointerException
Continuing ...
java.lang.Exception: discarding statement XMLEncoder0.writeObject(Integer0);
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
</java>

4) ERROR BUG!!!!!!!!! Nothing is encode
ava.lang.NullPointerException
Continuing ...
java.lang.Exception: discarding statement XMLEncoder0.writeObject(Integer0);
Continuing ...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.4.2_03" class="java.beans.XMLDecoder">
</java>

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
the applet code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.io.ByteArrayOutputStream;
import java.io.BufferedOutputStream;

public class Applethtml
    extends Applet {
  private boolean isStandalone = false;
  JPanel jPanel1 = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  JTextPane jTextPane1 = new JTextPane();
  JButton jButton = new JButton();
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
        (getParameter(key) != null ? getParameter(key) : def);
  }

  public Applethtml() {}

  public void init() {
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    jPanel1.setLayout(borderLayout1);
    jTextPane1.setText("Exemple");
    jButton.setText("Get");
    jButton.addKeyListener(new Applethtml_jButton_keyAdapter(this));
    this.addMouseListener(new Applethtml_this_mouseAdapter(this));
    this.addMouseListener(new Applethtml_this_mouseAdapter
                          (this));
    this.add(jPanel1, null);
    this.add(jTextPane1, null);
    this.add(jButton, null);
  }

  public void start() {}

  public void stop() {}

  public void destroy() {}

  public String getAppletInfo() {
    return "Information applet";
  }

  public String[][] getParameterInfo() {
    return null;
  }

  public String getDocument(String obj) {
    String enc = encode( (Object) obj);
    System.out.println(enc);
    return enc;
  }

  public String getDocument(Integer obj) {
    System.out.println("String getDocument(Integer obj)");
    String enc = encode( (Object) obj);
    System.out.println(enc);
    return enc;
  }

  public String getDocument() {
    Integer obj = new Integer(22);
    System.out.println( (Object) obj);
    String enc = encode( (Object) obj);
    System.out.println(enc);
    return enc;
  }

  private String encode(Object obj) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    baos.reset();
    java.beans.XMLEncoder xmlencoder = new java.beans.XMLEncoder(new
        BufferedOutputStream(baos));
    xmlencoder.writeObject(obj);
    xmlencoder.close();
    return
        baos.toString();
  }

  String jButton_keyPressed(KeyEvent e) {
    String codeRetour = (String) getDocument(new Integer(22));
    System.out.println("RESULT: " + codeRetour);
    return codeRetour;
  }

  String this_mouseClicked(MouseEvent e) {
    String codeRetour = (String) getDocument(new Integer(33));
    System.out.println("RESULT: " + codeRetour);
    return codeRetour;
  }
}

class Applethtml_jButton_keyAdapter
    extends java.awt.event.KeyAdapter {
  Applethtml adaptee;
  Applethtml_jButton_keyAdapter(Applethtml adaptee) {
    this.adaptee = adaptee;
  }

  public void keyPressed(KeyEvent e) {
    adaptee.jButton_keyPressed(e);
  }
}

class Applethtml_this_mouseAdapter
    extends java.awt.event.MouseAdapter {
  Applethtml adaptee;
  Applethtml_this_mouseAdapter(Applethtml adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.this_mouseClicked(e);
  }
}

----------------------------------------------------------------------------------------------------
htmlfile:

<html>
  <head>
    <title> test_HTML</title>
    </head>
    <body>Exemple test<br>
      <applet  codebase = "."
        code     = "Applethtml.class"
archive="Applethtml.jar"
        name     = "AppletTest"
        width    = "400"
        height   = "300"
        hspace   = "0"
        vspace   = "0"
        align    = "middle">
        </applet>
        <BR>
          <input type="button"
            value="String 22"
            onClick="alert(AppletTest.getDocument('22'))">
            <input type="button"
              value="Integer 22 passed by script"
              onClick="alert(AppletTest.getDocument(22))">
              <input type="button"
                value="Integer 22 hardcoded in applet"
                onClick="alert(AppletTest.getDocument())">
                </body>
                </html>



---------- END SOURCE ----------
###@###.### 2004-12-06 21:12:47 GMT

Comments
EVALUATION This bug with original test case is not reproducible since the bug 4452032 was fixed. But attached test shows that the problem is not related to JavaBeans. See bug 6495348.
14-11-2006

EVALUATION The cause of the bug: Thread.currentThread().getContextClassLoader() returns null in some cases.
20-10-2006

EVALUATION It will be fixed when bug 4452032 is fixed, because packages java.beans and com.sun.beans contain wrong usages of Class.forName.
19-10-2006

EVALUATION This is IE only bug (context class loader is null). It can be fixed with bug 5006809.
12-10-2006

WORK AROUND add below permission to your policy file, permission java.lang.RuntimePermission "setContextClassLoader"; then add below lines into encode() in Applethtml.java as below private String encode(Object obj) { // add the line Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.reset(); java.beans.XMLEncoder xmlencoder = new java.beans.XMLEncoder(new BufferedOutputStream(baos)); xmlencoder.writeObject(obj); xmlencoder.close(); return baos.toString(); }
02-12-2005

EVALUATION reproduced in mustang as well. the bug is caused by null context classloader of calling thread. That's is, XMLEncoder uses context class loader internally for java.lang.Integer, but it can tolerate null context class loader for java.lang.String. when JS call Java, the context class loader is null, so this bug happens. XMLEncoder should use other classloaders if context classloader is null.
02-12-2005

EVALUATION this is not JAXP related, bug is being reassigned to java/java_plugin/other.
30-11-2005

EVALUATION It is not jaxp bug. java.beans.XMLEncoder is not developed by JAXP Team. Please change product category. thx -Suresh
10-11-2005

EVALUATION The "Integer 22 hardcoded in applet" case (calling AppletTest.getDocument()) also fails with Firefox or Mozilla browser. So it's not an IE specific issue. Since the exception is coming from java.beans.XMLEncoder.writeObject, I'm transferring this bug to jaxp for further investigation.
02-11-2005