Closed Bug 424067 Opened 16 years ago Closed 11 years ago

Java in Firefox Extensions error while creating java.net.URL array

Categories

(Core Graveyard :: Java: OJI, defect)

x86
Linux
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: deus.ex.makina, Assigned: danielle.pham)

Details

(Keywords: regression)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9b5pre) Gecko/2008032000 Minefield/3.0b5pre XPCOMViewer/1.0a1
Build Identifier: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9b5pre) Gecko/2008032000 Minefield/3.0b5pre XPCOMViewer/1.0a1

Can't load a Java class due to is not possible to create java.net.URL[]

Reproducible: Always

Steps to Reproduce:
1. init a javascript shell
2. var u = [java.net.URL('http://foo.net/bar.jar')]
3. var c = new java.net.URLClassLoader(u);
(http://developer.mozilla.org/en/docs/Java_in_Firefox_Extensions)
Actual Results:  
Unable to convert JavaScript value http://foo.net/bar.jar to Java value of type java.net.URL[]


Tested in firefox:
Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.9b5pre) Gecko/2008032000 Minefield/3.0b5pre XPCOMViewer/1.0a1
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9b5pre) Gecko/2008031922 Minefield/3.0b5pre

This happens since firefox 3.0b4
Version: unspecified → Trunk
I confirm this bug on 
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9pre) Gecko/2008033113 Minefield/3.0pre

This bug prevents my extension openinfocard "Information Cards for Firefox" from working. In early version of Firefox 3 the extension crashed Firefox3. Now it is not crashing but still not working. Please don't publish a 3.0pre version with this bug!
My extension is here:
http://code.google.com/p/openinfocard/downloads/list
Flags: blocking-firefox3?
and which version of java are you using? and which version of firefox/java were you using before?
Component: Extension Compatibility → Java: OJI
Flags: blocking-firefox3?
Product: Firefox → Core
QA Contact: extension.compatibility → java.oji
about:plugins
    File name: npoji610.dll
    Java Plug-in 1.6.0_05 for Netscape Navigator (DLL Helper) java version "1.6.0_05"

------------ java -version -------------
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

----------------------------------------

InternalError: Unable to convert JavaScript value file:/C:/Dokumente%20und%20Einstellungen/Nennker.Axel/Anwendungsdaten/Mozilla/Firefox/Profiles/kb7ofbop.default/extensions/%7B211DBAEA-CE99-11DA-8254-96BEC52F3316%7D/components/firefoxClassLoader.jar to Java value of type java.net.URL[]

-----------------------------------------

The java version is not the problem. This works with Firefox 2.0* but fails with the Firefox3 betas. The first betas crashed when the openinfocard extension loads the java component. The current betas don't crash but the java xpcom does not work due to the "InternalError:" above.
abouts:plugins
Java(TM) Plug-in 1.6.0_05-b13

    File name: libjavaplugin_oji.so
    Java(TM) Plug-in 1.6.0_05

As I said before, the problem started in firefox 3.0b4
java version "1.5.0_15"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
Java HotSpot(TM) Client VM (build 1.5.0_15-b04, mixed mode, sharing)

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b4) Gecko/2008030318 Firefox/3.0b4

About:Plugins
    File name: libjavaplugin_oji.so
    Java(TM) Plug-in 1.5.0_15


I confirm that error for the above versions.
I found a way to circumvent this bug.

In a javascript script the call "java_method([aElement])" formerly worked but now it fails. It has to be replaced with
var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, 1);
urlArray[0] = aElement; // aElement beeing a java.net.URL
java_method(urlArray);

This method works for types other than java.net.URL too.
e.g.: http://code.google.com/p/openinfocard/source/browse/trunk/firefox/components/TokenComponent.js#460 

http://ignisvulpis.blogspot.com/2008/04/minefield-defused.html
Assignee: nobody → danielle.pham
Keywords: regression
Have you tried the new NPRuntime-based Java Plug-In in conjunction with the FF 3.0 early access builds?

http://jdk6.dev.java.net/6u10ea.html
No. My comments above list all combinations that I tried.
I the meantime I upgraded my java version. So I retested this bug today:

I downloaded the latest mozilla source code from CVS and rebuilt the browser. 

Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9pre) Gecko/2008042910 Minefield/3.0pre

I started the new browser and downloaded xmldap-0.9.9.20080401.xpi from the openinfocard project's download area and installed it into the new browser.
http://code.google.com/p/openinfocard/downloads/list

Now I opened https://xmldap.org/relyingparty/ and clicked the image. This startsed the identity selector, I chose a card and everything worked fine.

I currently use this java version:
$ java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
I verified that minefield uses the same version (about:plugins).

Next I changed the code of my extension to use the old-not-working javascript contruct.
http://code.google.com/p/openinfocard/source/browse/trunk/firefox/components/TokenComponent.js#265
This not-working code looks like:
    var firefoxClassLoaderURL = 
        new java.net.URL(extensionPath + "components/firefoxClassLoader.jar");
    //var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, 1);
    //urlArray[0] = firefoxClassLoaderURL;
    
    /*
     *  Step 1. Load the bootstraping firefoxClassLoader.jar.
     */
    var bootstrapClassLoader = java.net.URLClassLoader.newInstance([firefoxClassLoaderURL]); // here is the bug
    if (!(bootstrapClassLoader instanceof java.net.URLClassLoader)) {
        _printToJSConsole("Error: java.net.URLClassLoader.newInstance failed! " + bootstrapClassLoader);
    }

Then I rebuild the openinfocard extension, installed it and tried it at xmldap.org/relyingparty/. This still does not work:
InternalError: Unable to convert JavaScript value file:/C:/Dokumente%20und%20Einstellungen/Axel%20Nennker/Anwendungsdaten/Mozilla/Firefox/Profiles/o71lzy3u.minefield/extensions/%7B211DBAEA-CE99-11DA-8254-96BEC52F3316%7D/components/firefoxClassLoader.jar to Java value of type java.net.URL[]

To me this looks like the javascript interpreter is overlooking the square brackets around firefoxClassLoaderURL in line 271. I expect this behaviour:
- js interpreter (jsi) parses the function call ( newinstance([firefoxClassLoaderURL]) )
- jsi parses arg (  [firefoxClassLoaderURL] ) and constructs a js array of objects
- jsi tries to find matching function and detects that a java array of URL would match
- jsi converts js array of object to java array of URL
- jsi calls java function "newinstance" with java array of URL as parameter.

So I expect the error to be in mozilla/js/src/* somewhere and NOT in java; but you are the expert. I am just guessing but my guess is that trying it with 6u10ea is a waste of time.



I wrote a little test to verify the 2 cases reported by Oriol Mula & Axel Nennker:

<html>
<body>
<script language="javascript" type="text/javascript">
function FuncOriol() {
var u = [java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar')]; 
var c = new java.net.URLClassLoader(u);
alert(c.toString());
}

function FuncAxel() {
var jarURL = new java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar');
var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, 1);
//urlArray[0] = jarURL;
//alert("Hello: " + urlArray[0].toString());
}
</script>

<button onclick="FuncOriol()">Oriol's testcase</button>
<button onclick="FuncAxel()">Axel's testcase</button>

</body>
</html>

(Note that: if you're using any JRE version older than 6u10, it's OJI Plugin that's used.  NPRuntime Java Plugin is the new generation Java Plugin that will be the default starting 6u10, and will eventually replace OJI Plugin. NPRuntime Java Plugin requires FF3 to work.
For latest 6u10 build, goto: http://jdk6.dev.java.net/6u10ea.html).

I tested with FF3 and 6u10's OJI Java Plugin and NPRuntime Java Plugin, and here's what I saw:

1) Oriol's testcase & OJI Plugin: I confirmed that JS parser fails to parse this line correctly:
var u = [java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar')];
and var c = new java.net.URLClassLoader(u); will result in the following JS error:

"Unable to convert JavaScript value http://javaweb.sfbay/~dp144265/miscs/test.jar to Java value of type java.net.URL[]"

This is a problem with FF3's JS parser. So from Sun, we cannot do anything about it. Johnny, could you please help take a look.

2) Oriol's testcase & NPRuntime plugin: 
The following JS error is received when parsing this line:
var u = [java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar')];

"Attempt to call a default method on object with no invokeDefault method"

Again, this is a problem with the JS parser. Johnny may be able to help.

3) Axel's testcase with OJI Plugin:  works fine as indicated by Axel.

4) Axel's testcase with NPRuntime Plugin: 
This line:
var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, 1);
results in a Java Exception:
java.lang.IllegalArgumentException: No method found matching name newInstance and arguments [sun.plugin2.liveconnect.JavaNameSpace, java.lang.Integer]
	at sun.plugin2.liveconnect.JavaClass$MemberBundle.invoke(Unknown Source)
	at sun.plugin2.liveconnect.JavaClass.invoke(Unknown Source)
	at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$JavaNameSpaceProxy.invoke(Unknown Source)
	at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo.doObjectOp(Unknown Source)
	at sun.plugin2.main.client.LiveConnectSupport$PerAppletInfo$LiveConnectWorker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Apparently, NPRuntime plugin returns sun.plugin2.liveconnect.JavaNameSpace JavaClass for the 'java.net.URL' argument.  This is a bug with NPRuntime plugin.
I will file a Sun bug on this so we can work on it.
Sun CR#6695751 has been created to track above problem (4) with NPRuntime Plugin in JRE 6u10.

Johnny, could you please take a look at problems (1) and (2) in my previous post.

Thanks. 
The syntax

[java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar')]

is invalid. You need to write

[new java.net.URL('http://javaweb.sfbay/~dp144265/miscs/test.jar')]

I was unaware of the syntax in JavaScript 1.4 to refer to Class objects directly via e.g.

var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, 1);

This is an RFE for the new Java Plug-In at this point. You can achieve the same result with

var urlArray = java.lang.reflect.Array.newInstance(java.lang.Class.forName("java.net.URL"), 1);
This still does not work with Firefox 3 RC1:

"InternalError: Unable to convert JavaScript value file:/C:/Dokumente%20und%20Einstellungen/Nennker.Axel/Anwendungsdaten/Mozilla/Firefox/Profiles/kb7ofbop.default/extensions/%7B211DBAEA-CE99-11DA-8254-96BEC52F3316%7D/components/firefoxClassLoader.jar to Java value of type java.net.URL[]".
This is fixed with java6u12.
Product: Core → Core Graveyard
Mass-closing bugs in the "OJI" component: OJI plugin integration was replaced with npruntime long ago, and these bugs appear to be irrelevant now. If there is in fact a real bug that remains, please file it new in the "Core" product, component "Plug-ins".
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.