Skip to content

Commit

Permalink
Avoid null crashes when getting instance path (getodk#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and lognaturel committed Aug 8, 2018
1 parent ef6454e commit d44b2df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ private void nonblockingCreateSavePointData() {
}
}

@Nullable
private FormController getFormController() {
return Collect.getInstance().getFormController();
}
Expand Down Expand Up @@ -2107,8 +2108,10 @@ private void removeTempInstance() {
}
}

@Nullable
private String getAbsoluteInstancePath() {
return getFormController().getInstanceFile().getAbsolutePath();
FormController formController = getFormController();
return formController != null ? formController.getAbsoluteInstancePath() : null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,26 @@ public static boolean isInstanceComplete(boolean end) {
}

public static Uri getLastInstanceUri(String path) {
try (Cursor c = new InstancesDao().getInstancesCursorForFilePath(path)) {
if (c != null && c.getCount() > 0) {
// should only be one...
c.moveToFirst();
String id = c.getString(c.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID));
return Uri.withAppendedPath(InstanceProviderAPI.InstanceColumns.CONTENT_URI, id);
if (path != null) {
try (Cursor c = new InstancesDao().getInstancesCursorForFilePath(path)) {
if (c != null && c.getCount() > 0) {
// should only be one...
c.moveToFirst();
String id = c.getString(c.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID));
return Uri.withAppendedPath(InstanceProviderAPI.InstanceColumns.CONTENT_URI, id);
}
}
}
return null;
}

public static boolean isInstanceAvailable(String path) {
boolean isAvailable = false;
try (Cursor c = new InstancesDao().getInstancesCursorForFilePath(path)) {
if (c != null) {
isAvailable = c.getCount() > 0;
if (path != null) {
try (Cursor c = new InstancesDao().getInstancesCursorForFilePath(path)) {
if (c != null) {
isAvailable = c.getCount() > 0;
}
}
}
return isAvailable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public void setInstanceFile(File instanceFile) {
this.instanceFile = instanceFile;
}

@Nullable
public String getAbsoluteInstancePath() {
return instanceFile != null ? instanceFile.getAbsolutePath() : null;
}

public void setIndexWaitingForData(FormIndex index) {
indexWaitingForData = index;
}
Expand Down

0 comments on commit d44b2df

Please sign in to comment.