[ 
https://issues.apache.org/jira/browse/CB-12218?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16307647#comment-16307647
 ] 

Hideto KIHARA commented on CB-12218:
------------------------------------

There are two routes which uses different message encoding on native to JS 
message.
(on EvalBridgeMode)

If route2 is used, null becomes "".
Because popAndEncodeJs() does not support null.

{noformat}
* route1 (popAndEncode()):
  CordovaBridge#jsExec()
  -> [plugin calls CallbackContext#sendPluginResult()]
  -> NativeToJsMessageQueue#popAndEncode()
* route2 (popAndEncodeJs()):
  CordovaBridge#jsExec()
  -> [plugin starts new thread and returns immediately from execute()]
  -> (NativeToJsMessageQueue#popAndEncode(). no message in queue yet)
    -> [plugin thread calls CallbackContext#sendPluginResult()]
    -> EvalBridgeMode#onNativeToJsMessageAvailable()
    -> NativeToJsMessageQueue#popAndEncodeJs()
{noformat}

null becomes "" by JSONObject.quote(null) in PluginResult#getMessage().

(It may be better to add a method calculateJsEncodedLength().
Because calculateEncodedLength() does not consider encodeAsJsMessage())

I wrote sample plugin and cordova-paramedic tests to reproduce this issue:
https://github.com/deton/cordova-plugin-nullresulttest


> inconsistent null handling between EVAL and ONLINE bridge modes
> ---------------------------------------------------------------
>
>                 Key: CB-12218
>                 URL: https://issues.apache.org/jira/browse/CB-12218
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-android
>    Affects Versions: 6.0.0
>         Environment: Android
>            Reporter: Alan Kinzie
>            Assignee: Joe Bowser
>         Attachments: CB12218.zip
>
>
> If the Android native code invokes the success callback like this:
> callbackContext.success(null);
> then the value given to the javascript callback changes depending on the 
> bridge type used.
> If the ONLINE_EVENT type is used, then null will be passed to the javascript 
> callback.
> ie: if result is the parameter of the javascript success callback then
> result === null  // will be true
> result === "" // will be false
> If the EVAL_BRIDGE type is used, then an empty string will be passed to the 
> javascript callback.
> ie: if result is the parameter of the javascript success callback then
> result === null  // will be false
> result === "" // will be true
> The value of the parameter given to the success callback should not change 
> depending on the bridge type.  Since ONLINE_EVENT was the default before 
> cordova android 6.0.0, I am inclined to think the ONLINE bridge is doing the 
> correct behaviour.  Also, converting null to an empty string loses 
> information.  Therefore I think the EVAL mode should to be changed to be 
> consistent with the ONLINE mode.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to