android/source/src/java/org/libreoffice/ui/FileUtilities.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
New commits: commit 0b463cbc22d00f40055983c213c505c60064289a Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed May 4 07:17:01 2022 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed May 4 13:34:09 2022 +0200 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.wegh...@posteo.de> 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