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)
ADDITIONAL OS VERSION INFORMATION :
Windows 2000
EXTRA RELEVANT SYSTEM CONFIGURATION :
Internet Explorer 6
A DESCRIPTION OF THE PROBLEM :
This problem is new to JDK 1.5. There was no problem in JDK 1.4
When a method in a Java applet returns a String:
public String getS() { return "Hello!"; }
and that method is called from JavaScript:
var s = applet1.getS();
Then the return value of the method is not a native JavaScript string but is an object.
typeof(s) is "object" not "string"
As a result, the built-in JavaScript methods of String (like substr or match) cannot be used.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create a simple applet with a public method that returns a String.
public String getS() { return "Hello!"; }
2. Call that method from JavaScript on a web page:
var s = applet1.getS();
3. Examine typeof(s) or try to call s.substr(0,1)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
typeof(s) should be "string"
s.substr(0,1) should be "H"
ACTUAL -
typeof(s) is "object"
s.substr(0,1) results in an "Unspecified error"
ERROR MESSAGES/STACK TRACES THAT OCCUR :
"Unspecified error"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
You need the following 2 files: a Java applet and an HTML page. They have to be in the same folder, and the Java code has to be compiled.
******************************
Here is the applet:
package bugdemo;
import java.awt.Color;
public class JsStringsApplet extends java.applet.Applet
{
public String helloField = "Hello (field)!";
public String getHelloMethod()
{
return "Hello (method)!";
}
public void init()
{
super.init();
System.out.println( "JsStringsApplet - init'ing..." );
this.setBackground( Color.lightGray );
this.setForeground( Color.black );
}
}
*********************************************
and here is the page:
<HTML>
<HEAD>
</HEAD>
<BODY>
<P> </P>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
name=JsStringsApplet2
width="200" height="100" VIEWASTEXT>
<PARAM name="code" value="bugdemo.JsStringsApplet.class">
<xPARAM name="codebase" value="http://localhost/jsp">
<PARAM name="codebase" value="../">
<PARAM name="type" value="application/x-java-applet">
<PARAM name="scriptable" value="true">
<param name=label value="This string was passed from the HTML host.">
<param name=background value="008080">
<param name=foreground value="FFFFFF">
No Java 2 SDK, Standard Edition v 1.5.0 support for APPLET!!
</OBJECT>
<input type=button value="Test Applets" onclick="testApplets()">
<script>
function testApplets()
{
showValue( JsStringsApplet2.getHelloMethod() );
showValue( JsStringsApplet2.helloField );
alert( JsStringsApplet2.helloField.substr(0,1) );
}
function showValue( v )
{
alert( typeof(v) );
alert( v );
}
</script>
</BODY>
</HTML>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
var s = applet1.getS(); // s is an object not a string
s = String(s); // now s is a string
But of course, this workaround is not practical for large JavaScript applications
Release Regression From : 1.4.2
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
###@###.### 10/27/04 19:56 GMT