String.replace fails when used inside a function that is called by an applet using Live connect



Core Graveyard
Java: OJI
14 years ago
7 years ago


(Reporter: Sanket Gupta, Assigned: Kyle Yuan)


Firefox Tracking Flags

(Not tracked)




14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6a) Gecko/20031030
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6a) Gecko/20031030

i was developing an applet which was calling a javascript function.this is being
established using live connect.The function call goes correctly and the function
seems to be working fine except in one case.
If i make a call to a String.replace function the code does not seem to execute.

I tried Mozilla 1.5, 1.6a , netscape 7 ,firebird on windows.
then i rebooted and tried on linux
Mozilla on linux also gave the same error.

But the same code works in IE on windows and Konqueror in Linux

So this seems like a bug in mozilla.

In essence the function execution is terminated.
I checked the  javascript and java consoles!No errors were reported.

Reproducible: Always

Steps to Reproduce:
if i use the simple code 
var Message="hello";
alert("Trying to replace");

alert("replace complete");
alert("Replace not supported");
</script> on a webpage it works.
But if i put the same code inside a function and when my applet calls it with
the string as an argument the code does not execute.
Also no subsequent code that comes after the call to string.replace is executed.
Actual Results:  
The function string replace should replace the regex with the new string!
Nothing of that sort happens.
Statements after this call are also not executed.
In essence the function execution is terminated.
I checked the  javascript and java consoles!No errors were reported.

Comment 1

14 years ago
This sounds similar to a number of other issues that OJI is considering.
Reassigning to Java:OJI component for further triage -
Assignee: live-connect → kyle.yuan
Component: Java: Live Connect → Java: OJI
Ever confirmed: true

Comment 2

14 years ago
Setting default QA -
QA Contact: PhilSchwartau → general

Comment 3

14 years ago
Nothing to do with Java. 

Comment 4

14 years ago
The fact is the function fails only when a call to the function is made from a 
java applet.All the rest of the calls seem to be working.
so it must be a bug in java live connect or something.

I am not a mozilla developer so i dont know the exact words.
My code  works in IE and konqueror so it must also work in Mozilla.
But it fails to work and that problem must be solved.
Sanket Gupta

Comment 5

14 years ago
it works for me on both Windows 2000 & Linux.

Here is my test case. You can see what the difference is.

<applet id="testApplet" code="TestLC.class" MAYSCRIPT="true">
function stringreplace(oldstr, newstr) {
    var Message = "hello";
    Message = Message.replace(oldstr, newstr);


import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import netscape.javascript.JSObject;
import netscape.javascript.JSException;

public class TestLC extends Applet implements ActionListener {

    JSObject win = null;

    public void init() {
        Button b1 = new Button("call");

    public void actionPerformed(ActionEvent e) {
        String arg = e.getActionCommand();

        try {
            win = (JSObject)JSObject.getWindow(this);
            if (win == null) {
                System.out.println("JSObject win = null");

            if (arg.equals("call")) {
        } catch (JSException ex) {

    private void test_call() throws JSException
        String args[] = new String[2];
        args[0] = "ello";
        args[1] = "handsome";"stringreplace", args);    

Comment 6

14 years ago
I tried your code and i agree that it works.
But the fact is that it fails to work in my code.The function call goes in 
smoothly and any statements that come before the replace function are executed 
So it definately isa  mozilla bug

One thing is that my applet is a mustithreaded socket based applet which 
recieves incoming data and displays tha data using javascript.
Before it displays the data some strings have to be replaced and thats where 
the problem occurs.
Can it be an error in the way mozilla handles multithreaded applets?
I am not sure what else to say.

Comment 7

14 years ago
My test case proves that java->javascript call works. For your case , it's
either the problem in your code or like you said, some problem with the
multithread applets. But without test case, I'm afraid we can do nothing for this.

Comment 8

14 years ago
WFM. Feel free to reopen it if you are still seeing this bug.
Last Resolved: 14 years ago
Resolution: --- → WORKSFORME

Comment 9

14 years ago
(In reply to comment #8)
> WFM. Feel free to reopen it if you are still seeing this bug.

Well i stopped using that function for now.Basically i rewrote the function 
call myself in javascript.Thats the best solution i had.


7 years ago
Component: Java: OJI → Java: OJI
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.