Closed
Bug 434658
Opened 17 years ago
Closed 17 years ago
Liveconnect use of JS array as Java array is broken
Categories
(Core Graveyard :: Java: Live Connect, defect)
Tracking
(Not tracked)
RESOLVED
WORKSFORME
People
(Reporter: brettz9, Unassigned)
Details
Attachments
(1 file)
|
1.03 KB,
application/x-javascript
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0
After one has built a JavaScript array (at least one which has Liveconnect Java objects within), that array cannot be processed (as part of a call to a Java method expecting a Java array). This used to work.
Reproducible: Always
Steps to Reproduce:
(Code samples adapted from http://simile.mit.edu/repository/java-firefox-extension/firefox/chrome/content/scripts/browser-overlay.js under license at http://simile.mit.edu/repository/java-firefox-extension/LICENSE.txt )
1.
Create a Java object:
var firefoxClassLoaderURL =
new java.net.URL(
PATH + "java/javaFirefoxExtensionUtils.jar"
);
2.
Add the Java object to a JavaScript array and pass it to a Java method.
var bootstrapClassLoader = java.net.URLClassLoader.newInstance(
[ firefoxClassLoaderURL ]
);
Actual Results:
The method doesn't work.
Expected Results:
The method should accept the array as though it were a Java array with Java object(s) inside.
Workaround:
Convert to appropriate typed Java array using reflection
Per http://simile.mit.edu/repository/java-firefox-extension/firefox/chrome/content/scripts/browser-overlay.js , it was necessary to "Explicitly construct Java array objects because Firefox 3 beta 4 and later don't seem to cast Javascript arrays into Java arrays automatically."
I can confirm that FF 3 RC 1 also has this problem.
// Note: Adapt to Java array type if not java.net.URL
// Pass in a JavaScript array to get the equivalent Java array
var toUrlArray = function(a) {
var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, a.length);
for (var i = 0; i < a.length; i++) {
var url = a[i];
java.lang.reflect.Array.set(
urlArray,
i,
(typeof url == "string") ? new java.net.URL(url) : url
);
}
return urlArray;
};
See this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=434101
Updated•17 years ago
|
Component: General → Java: Live Connect
Product: Firefox → Core
QA Contact: general → live-connect
Version: unspecified → Trunk
Comment 2•17 years ago
|
||
Brett, can you create and attach a testcase?
| Reporter | ||
Comment 3•17 years ago
|
||
Not sure if this is what you had in mind for a test case, but I think it demonstrates the problem succinctly
| Reporter | ||
Comment 4•17 years ago
|
||
Somewhat off topic comment, but while LiveConnect bugs are being discussed, I see the try-catch problems described at https://bugzilla.mozilla.org/show_bug.cgi?id=391642 as a far more serious bug (since this array bug has an easy JAVASCRIPT workaround) if there's any hope LiveConnect bugs may be fixed.
But on #developers, "jst_home__,isnick" mentioned to me that "LiveConnect is going away", "LiveConnect will not ship with the next Firefox version (whatever's after 3.0.x)" and "LiveConnect is a mess, a big one, and an unowned one, which is why it's going away"
Comment 5•17 years ago
|
||
Yes, Liveconnect has already been disabled on mozilla-central (what will become Firefox 3.1). See bug 397080.
| Reporter | ||
Comment 6•17 years ago
|
||
For those using LiveConnect and in the dark, it is being resurrected (and in a cross-browser way): https://jdk6.dev.java.net/plugin2/liveconnect/ . According to this posting at http://forums.java.net/jive/thread.jspa?threadID=45933&tstart=0 and the bug it refers to, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6745455 the new problem with extensions now not having privileges as before (which I think just started in Java 6 update 11, causing Mozilla extensions that depend on such code to become useless) is going to be fixed in update 12.
So now, fixing LiveConnect is dependent on Java itself, and adjusting to any changes in the new API (though most code seems like it will work just as before). However, since the new spec deprecates the java/netscape/Packages globals in favor of the new per-applet Packages, it is unclear to me whether Firefox extensions are supposed to include code like <html:applet...> and document.getElementById('app') (once the privileges fix mentioned in the thread above becomes available).
There are also apparently new goals (the file was modified recently) stated at http://www.mozilla.org/js/liveconnect/lc3_proposal.html
| Reporter | ||
Comment 7•17 years ago
|
||
This bug (for both extension code and applets), as with some other previous bugs introduced into the former LiveConnect over time, has now been resolved as of Java 6 update 12, with the
move to reimplementat LiveConnect. See
https://jdk6.dev.java.net/plugin2/#LIVECONNECT ,
https://jdk6.dev.java.net/plugin2/liveconnect/ ,
http://forums.java.net/jive/thread.jspa?threadID=45933&tstart=0
To address my earlier concern on globals being deprecated, per http://forums.java.net/jive/thread.jspa?threadID=45933&tstart=0 , for non-applet pages, "Firefox and the Java Plug-In will continue to support the global java/Packages keywords, in particular in the context of Firefox extensions...In the context of normal web pages embedding applets, it is strongly recommended to move to the portable per-applet Packages keyword.", so there is no need to try to insert XHTML applets into XUL code, etc., as the LiveConnect documentation might be taken to imply (by its mentioning the globals were deprecated).
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Comment 8•17 years ago
|
||
If a bug is fixed without interaction from the Mozilla team, such as via a Flash or Java update, the proper resolution is Works For Me.
Resolution: FIXED → WORKSFORME
You need to log in
before you can comment on or make changes to this bug.
Description
•