From 887f7540148c24fb11836038dd9dd403769e968d Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 25 Mar 2011 16:46:26 +0600 Subject: [PATCH] Hidden NPE fixed, which appeared when someone pass null as arguments (for such SQL as e.g. CREATE TABLE). It is especially important when work with dome 3d party persistemce libraries, like e.g. http://github.com/zefhemel/persistencejs which passes these nulls. --- framework/src/com/phonegap/Storage.java | 158 ++++++++++++++---------- 1 file changed, 91 insertions(+), 67 deletions(-) mode change 100755 => 100644 framework/src/com/phonegap/Storage.java diff --git a/framework/src/com/phonegap/Storage.java b/framework/src/com/phonegap/Storage.java old mode 100755 new mode 100644 index de30afb2..67fc6f3e --- a/framework/src/com/phonegap/Storage.java +++ b/framework/src/com/phonegap/Storage.java @@ -16,15 +16,15 @@ import android.database.Cursor; import android.database.sqlite.*; /** - * This class implements the HTML5 database support for Android 1.X devices. - * It is not used for Android 2.X, since HTML5 database is built in to the browser. + * This class implements the HTML5 database support for Android 1.X devices. It + * is not used for Android 2.X, since HTML5 database is built in to the browser. */ public class Storage extends Plugin { - - SQLiteDatabase myDb = null; // Database object - String path = null; // Database path - String dbName = null; // Database name - + + SQLiteDatabase myDb = null; // Database object + String path = null; // Database path + String dbName = null; // Database name + /** * Constructor. */ @@ -34,29 +34,37 @@ public class Storage extends Plugin { /** * Executes the request and returns PluginResult. * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackId The callback id used when calling back into JavaScript. - * @return A PluginResult object with a status and message. + * @param action + * The action to execute. + * @param args + * JSONArry of arguments for the plugin. + * @param callbackId + * The callback id used when calling back into JavaScript. + * @return A PluginResult object with a status and message. */ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; - String result = ""; - + String result = ""; + try { - // TODO: Do we want to allow a user to do this, since they could get to other app databases? + // TODO: Do we want to allow a user to do this, since they could get + // to other app databases? if (action.equals("setStorage")) { this.setStorage(args.getString(0)); - } - else if (action.equals("openDatabase")) { - this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3)); - } - else if (action.equals("executeSql")) { - JSONArray a = args.getJSONArray(1); - int len = a.length(); - String[] s = new String[len]; - for (int i=0; i