Skip to content

Commit

Permalink
Fix bug causing crash during upgrade - NPE when trying to cancel sche…
Browse files Browse the repository at this point in the history
…duled service alarm (where none existed)

Fixes codinguser#569
Log the target exception instead of the invocation wrapper exception when migrating the db
  • Loading branch information
codinguser committed Sep 5, 2016
1 parent b43b5dd commit a3927c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ apply plugin: 'io.fabric'

def versionMajor = 2
def versionMinor = 1
def versionPatch = 0
def versionBuild = 6
def versionPatch = 1
def versionBuild = 0

def buildTime() {
def df = new SimpleDateFormat("yyyyMMdd HH:mm 'UTC'")
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/org/gnucash/android/db/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
Crashlytics.logException(e);
throw new RuntimeException(e);
} catch (InvocationTargetException e){
Crashlytics.logException(e);
throw new RuntimeException(e);
Crashlytics.logException(e.getTargetException());
throw new RuntimeException(e.getTargetException());
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/org/gnucash/android/db/MigrationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -1466,9 +1466,11 @@ static int upgradeDbToVersion13(SQLiteDatabase db){
//cancel the existing pending intent so that the alarm can be rescheduled
Intent alarmIntent = new Intent(context, ScheduledActionService.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, alarmIntent, PendingIntent.FLAG_NO_CREATE);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
if (pendingIntent != null) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
pendingIntent.cancel();
}

GnuCashApplication.startScheduledActionExecutionService(GnuCashApplication.getAppContext());

Expand Down

0 comments on commit a3927c8

Please sign in to comment.