JDK-6179021 : Strings not returned properly from Java applet to Javascript
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-10-14
  • Updated: 2010-04-03
  • Resolved: 2005-02-11
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
Java Plug-in 1.5.0
Using JRE version 1.5.0 Java HotSpot(TM) Client VM

ADDITIONAL OS VERSION INFORMATION :
MS Windows 2000 SP 4. Build 5.00.2195.

EXTRA RELEVANT SYSTEM CONFIGURATION :
Running under IE 6. With latest patches

A DESCRIPTION OF THE PROBLEM :
When returning a String from Java Applet to javascript, under the latest Java plugin, it now preserves the String as a Java object and doesn't automatically convert the String to a javascript string.  This was working properly as of the v1.5.0 beta 1 plugin.  We regard this as not a bug since the Java to Javascript API has changed in a major way which no-one was notified about and as a result affects the majority of our system which does extensive javascript to java calls.  We now have customers which are not able to use our product under the Sun JVM, and must remain using the MS JVM since it would just be too costly to spend the time and resources on changing our codebase to workaround this issue. I'd imagine other developers/companies are in the same situation.  The problem is  apparent  when making calls to say substring, replace, length, split, and any equality or inequality checks and many other String api calls.

This is specific to using the plugin in IE.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Have two java method available on the applet
Java (applet API method called by JavaScript):
    public String  getUserString()    {
        String tmp = "Hello1"
        return tmp;
    }

2.  Call the java method from the javascript:
         var tmpStr1 = null;
         var tmpStr2 = null;
          tmpStr1 = applet.getUserString();
          tmpStr2 = applet.getUserString();

3. Use that expression in a javascript statement :
      if (tmpStr1 == tmpStr2) then ....
 
Also a more common problem in javascript  now is the use of length :
4.   var tmpStr3 = null;
      tmpStr3 = applet.getUserString();

     if (tmpStr3.length > 0)
  

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
In point 3, the expected results is that the if statement will evaluate to true.  This was the case up until beta 1 v1.5.0.

In point 4,  the expected results is that the if statement will evaluate to true.  This was the case up until beta 1 v1.5.0. This is because the java string would have been autmotically converted to a javascript  string and the length function would have been called on the javascript string with no problems.

ACTUAL -
In point 3, the actual result is that it returns false since the two string objects are not equal (since they are java objects),  and you must change the code to be

if tmpStr1.equals(tmpStr2) then ...

In point 4,  the actual result is that it raises an error since you are performing the .length operation on a java string object which doesnt exist.  The code works fine under the MS JVM.




REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
The only possible workaround is to always convert a Java object string to a javascript string at places where we call the java code in the applet which is unfeasible and unnessary especially since this was working up until beta release 1 of v1.5.0. And in order for the code to be compatible between MS and Sun JVMs the the changes are just to extensive.
###@###.### 10/14/04 08:22 GMT