You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Peter (JIRA)" <ji...@apache.org> on 2013/05/30 05:21:20 UTC

[jira] [Created] (CB-3548) Error handling in onJsPrompt not working

Peter created CB-3548:
-------------------------

             Summary: Error handling in onJsPrompt not working
                 Key: CB-3548
                 URL: https://issues.apache.org/jira/browse/CB-3548
             Project: Apache Cordova
          Issue Type: Bug
          Components: Android
    Affects Versions: 2.7.0
            Reporter: Peter
            Assignee: Joe Bowser
            Priority: Critical


(This is a contrived scenario written to try to understand the bridging implementation)

It seems the error handling in the onJsPrompt() bridge in CordovaChromeClient.java is not working correctly.

{code}
        if (reqOk && defaultValue != null && defaultValue.length() > 3 && defaultValue.substring(0, 4).equals("gap:")) {
            JSONArray array;
            try {
                array = new JSONArray(defaultValue.substring(4));
                String service = array.getString(0);
                String action = array.getString(1);
                String callbackId = array.getString(2);
                String r = this.appView.exposedJsApi.exec(service, action, callbackId, message);
                result.confirm(r == null ? "" : r);
            } catch (JSONException e) {
                e.printStackTrace();
            }
{code}

---

If JSONException occurs then my application fails and cannot recover. For example, try below.

{code}
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
var one=prompt("test1","Harry Potter");
var two=prompt("test2","gap: abc");
}
</script>
{code}

---

But if I modify the onJsPrompt code as follows then it behaves more gracefully:

{code}
            } catch (JSONException e) {
                e.printStackTrace();
                return false; // added
            }
{code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira