Skip to content

Commit cd8bdb7

Browse files
committed
Use try-with-resources in BooksDBAdapter.getActiveBookUID()
1 parent 4904c20 commit cd8bdb7

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

app/src/main/java/org/gnucash/android/db/adapter/BooksDbAdapter.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,24 @@ public boolean isActive(String bookUID){
154154
* @return GUID of the active book
155155
*/
156156
public @NonNull String getActiveBookUID(){
157-
Cursor cursor = mDb.query(mTableName, new String[]{BookEntry.COLUMN_UID},
158-
BookEntry.COLUMN_ACTIVE + "= 1", null, null, null, null, "1");
159-
try{
157+
try (Cursor cursor = mDb.query(mTableName,
158+
new String[]{BookEntry.COLUMN_UID},
159+
BookEntry.COLUMN_ACTIVE + "= 1",
160+
null,
161+
null,
162+
null,
163+
null,
164+
"1")) {
160165
if (cursor.getCount() == 0) {
161166
NoActiveBookFoundException e = new NoActiveBookFoundException(
162-
"There is no active book in the app."
163-
+ "This should NEVER happen, fix your bugs!\n"
164-
+ getNoActiveBookFoundExceptionInfo());
167+
"There is no active book in the app."
168+
+ "This should NEVER happen, fix your bugs!\n"
169+
+ getNoActiveBookFoundExceptionInfo());
165170
Crashlytics.logException(e);
166171
throw e;
167172
}
168173
cursor.moveToFirst();
169174
return cursor.getString(cursor.getColumnIndexOrThrow(BookEntry.COLUMN_UID));
170-
} finally {
171-
cursor.close();
172175
}
173176
}
174177

0 commit comments

Comments
 (0)