summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2022-05-04 07:17:01 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2022-05-04 13:34:09 +0200
commit0b463cbc22d00f40055983c213c505c60064289a (patch)
tree791fe04b91f2c77321e7e79c0f3dd7683c1b76bd /android
parent4fb2a667a634d04cbb72f005e7a74b4f29af0f81 (diff)
android: Make clear that column index is non-negative
Use `Cursor#getColumnIndexOrThrow` instead of `Cursor#getColumnIndex` here, as suggested in the `Cursor#getColumnIndex` doc [1]: > Returns the zero-based index for the given column name, or -1 if the > column doesn't exist. If you expect the column to exist use > getColumnIndexOrThrow(java.lang.String) instead, which will make the > error more clear. As described in the `OpenableColumns` doc [2], `OpenableColumns.DISPLAY_NAME` is one of the two standard columns that must be supported: > These are standard columns for openable URIs. Providers that serve > openable URIs must support at least these columns when queried. Addresses this lint error: > .../android/source/src/java/org/libreoffice/ui/FileUtilities.java:139: Error: Value must be ≥ 0 [Range] > displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > Explanation for issues of type "Range": > Some parameters are required to in a particular numerical range; this check > makes sure that arguments passed fall within the range. For arrays, Strings > and collections this refers to the size or length. [1] https://developer.android.com/reference/android/database/Cursor#getColumnIndex(java.lang.String) [2] https://developer.android.com/reference/android/provider/OpenableColumns Change-Id: I946fcd32a905a4bb8c0527fc1199b9dcc52bccfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133798 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
-rw-r--r--android/source/src/java/org/libreoffice/ui/FileUtilities.java2
1 files changed, 1 insertions, 1 deletions
diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
index 52b92534947f..902b30ed7794 100644
--- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java
+++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
@@ -136,7 +136,7 @@ public class FileUtilities {
String[] columns = {OpenableColumns.DISPLAY_NAME};
cursor = resolver.query(docUri, columns, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
- displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
+ displayName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME));
}
} catch (SecurityException e) {
// thrown e.g. when Uri has become invalid, e.g. corresponding file has been deleted