Skip to content

Commit 8b54dbc

Browse files
#289 java.lang.NullPointerException in nl.xservices.plugins.accessor.AbstractCalendarAccessor.getActiveCalendars
1 parent 9b5d1e1 commit 8b54dbc

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-calendar",
3-
"version": "4.4.7",
3+
"version": "4.4.8-dev",
44
"description": "This plugin allows you to manipulate the native calendar.",
55
"cordova": {
66
"id": "cordova-plugin-calendar",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://apache.org/cordova/ns/plugins/1.0"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
id="cordova-plugin-calendar"
6-
version="4.4.7">
6+
version="4.4.8-dev">
77

88
<name>Calendar</name>
99

src/android/nl/xservices/plugins/Calendar.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,17 @@ private void listCalendars() {
222222
cordova.getThreadPool().execute(new Runnable() {
223223
@Override
224224
public void run() {
225-
JSONArray jsonObject = new JSONArray();
226225
try {
227-
jsonObject = Calendar.this.getCalendarAccessor().getActiveCalendars();
226+
JSONArray activeCalendars = Calendar.this.getCalendarAccessor().getActiveCalendars();
227+
if (activeCalendars == null) {
228+
activeCalendars = new JSONArray();
229+
}
230+
PluginResult res = new PluginResult(PluginResult.Status.OK, activeCalendars);
231+
callback.sendPluginResult(res);
228232
} catch (JSONException e) {
229233
System.err.println("Exception: " + e.getMessage());
230234
callback.error(e.getMessage());
231235
}
232-
PluginResult res = new PluginResult(PluginResult.Status.OK, jsonObject);
233-
callback.sendPluginResult(res);
234236
}
235237
});
236238
}
@@ -469,7 +471,7 @@ public void run() {
469471
private static String getPossibleNullString(String param, JSONObject from) {
470472
return from.isNull(param) || "null".equals(from.optString(param)) ? null : from.optString(param);
471473
}
472-
474+
473475
private void listEventsInRange(JSONArray args) {
474476
// note that if the dev didn't call requestReadPermission before calling this method and calendarPermissionGranted returns false,
475477
// the app will ask permission and this method needs to be invoked again (done for backward compat).
@@ -479,7 +481,7 @@ private void listEventsInRange(JSONArray args) {
479481
return;
480482
}
481483
try {
482-
final JSONObject jsonFilter = args.getJSONObject(0);
484+
final JSONObject jsonFilter = args.getJSONObject(0);
483485
JSONArray result = new JSONArray();
484486
long input_start_date = jsonFilter.optLong("startTime");
485487
long input_end_date = jsonFilter.optLong("endTime");
@@ -490,7 +492,7 @@ private void listEventsInRange(JSONArray args) {
490492
} else {
491493
l_eventUri = Uri.parse("content://calendar/instances/when/" + String.valueOf(input_start_date) + "/" + String.valueOf(input_end_date));
492494
}
493-
495+
494496
cordova.getThreadPool().execute(new Runnable() {
495497
@Override
496498
public void run() {
@@ -557,7 +559,7 @@ public void run() {
557559
callback.error(e.getMessage());
558560
}
559561
}
560-
562+
561563
public void onActivityResult(int requestCode, int resultCode, Intent data) {
562564
if (requestCode == RESULT_CODE_CREATE) {
563565
if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_CANCELED) {

src/android/nl/xservices/plugins/accessor/AbstractCalendarAccessor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ public final JSONArray getActiveCalendars() throws JSONException {
262262
},
263263
this.getKey(KeyIndex.CALENDARS_VISIBLE) + "=1", null, null
264264
);
265+
if (cursor == null) {
266+
return null;
267+
}
265268
JSONArray calendarsWrapper = new JSONArray();
266269
if (cursor.moveToFirst()) {
267270
do {

0 commit comments

Comments
 (0)