Bug 38745 - Java bridge type conversions are incorrect
Summary: Java bridge type conversions are incorrect
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: Java (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Steve Block
URL: http://jdk6.java.net/plugin2/liveconn...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-07 06:36 PDT by Ben Murdoch
Modified: 2022-06-22 22:25 PDT (History)
5 users (show)

See Also:


Attachments
Patch and layout test. (4.61 KB, patch)
2010-05-07 09:17 PDT, Ben Murdoch
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Murdoch 2010-05-07 06:36:59 PDT
If you try to pass a JS String over the jni bridge to a char in Java, then we try to convert the string to a number and pass that result to java. This behavior is correct except in the case that the JS String is one character long, in which case we should just pass the character itself without trying to convert to a number.

Patch and layout test to follow.
Comment 1 Ben Murdoch 2010-05-07 09:17:25 PDT
Created attachment 55383 [details]
Patch and layout test.
Comment 2 Alexey Proskuryakov 2010-05-07 09:45:59 PDT
I do not know why the new behavior is correct. There are several incompatible JNI specifications, and incompatible implementations. What are our reasons to make this change?

It's surprising that existing tests aren't affected by this change.
Comment 3 Ben Murdoch 2010-05-07 09:55:57 PDT
(In reply to comment #2)
> I do not know why the new behavior is correct. There are several incompatible
> JNI specifications, and incompatible implementations. What are our reasons to
> make this change?
> 

I noticed the current behavior while working on the V8 JNI bridge for Android - when passing a single character string from JS, Java was getting a garbage value in both JSC and V8. I tried the same test with Firefox, and they seem to use the behavior that this patch would provide. It also seems to follow the spec outlined in http://www.mozilla.org/js/liveconnect/lc3_method_overloading.html for conversion of JS Strings to Java chars. Perhaps there is a different spec that WebKit adopted for these type conversions, I'm not sure.

> It's surprising that existing tests aren't affected by this change.

I must admit I was surprised also. As far as I could tell though, the current tests don't verify the case where a single character is passed into Java from JS, just that a single character can be *returned* to JS, which works fine.
Comment 4 Alexey Proskuryakov 2010-05-07 10:24:40 PDT
I believe that the latest and greatest spec is at <https://jdk6.dev.java.net/plugin2/liveconnect/>. The driver for changes is a need to implement LiveConnect over NPAPI for out of process implementations. Also, current browsers don't match LiveConnect 3 in many cases anyway, so there is a need to converge on sensible and compatible behavior.

> Perhaps there is a different spec that WebKit adopted for these type conversions, I'm not sure.

WebKit behavior is probably close to LiveConnect 2, but with modifications to match other browsers and specs. It's definitely not cast in stone.
Comment 5 Ben Murdoch 2010-05-14 06:24:57 PDT
(In reply to comment #4)
> I believe that the latest and greatest spec is at <https://jdk6.dev.java.net/plugin2/liveconnect/>. The driver for changes is a need to implement LiveConnect over NPAPI for out of process implementations. Also, current browsers don't match LiveConnect 3 in many cases anyway, so there is a need to converge on sensible and compatible behavior.
> 
> > Perhaps there is a different spec that WebKit adopted for these type conversions, I'm not sure.
> 
> WebKit behavior is probably close to LiveConnect 2, but with modifications to match other browsers and specs. It's definitely not cast in stone.

Thanks for the pointer to that doc. I'll remove the review flag while I have a read and investigate what the other browsers do in this case and then I'll report back.

Thanks, Ben
Comment 6 Steve Block 2011-05-12 08:59:48 PDT
After discussion with Ben, I'm broadening this bug to track general conversion problems in the Java bridge
Comment 7 Steve Block 2011-05-12 09:01:45 PDT
One particular example from http://code.google.com/p/android/issues/detail?id=16311 - when a Java Object is passed to a method expecting java.lang.String, we should call toString() on the Object.
Comment 8 Steve Block 2011-05-12 09:11:12 PDT
That last link should have been http://code.google.com/p/android/issues/detail?id=16312

http://code.google.com/p/android/issues/detail?id=16311 describes a related problem when a JavaScript string is passed to a method expecting a Java Object, we should pass a new java.lang.String object.
Comment 9 Ahmad Saleem 2022-06-22 13:01:54 PDT
NPAPI support is removed from Safari 14 onward and it is not supported in Webkit Builds like WebkitGTK as well. I think this can be marked as "RESOLVED WONTFIX". Thanks!

Further, Java plugin support was removed even earlier in Safari 12. Also, Comment 08 is WONTFIX from Google as well. Thanks!
Comment 10 Ryosuke Niwa 2022-06-22 22:25:17 PDT
Yup, won't fix.