@@ -10,34 +10,50 @@ object CursorToVideoGsonConverter {
1010
1111 fun getVideoGson (cursor : Cursor ): VideoGson {
1212 Log .i(TAG , " getVideoGson" )
13-
1413 Log .i(TAG , " Arrays.toString(cursor.getColumnNames()): "
1514 + cursor.columnNames.contentToString())
16-
15+ if (cursor.isBeforeFirst && ! cursor.moveToFirst()) {
16+ throw IllegalArgumentException (" Cursor must be positioned on a valid row" )
17+ }
1718 val columnId = cursor.getColumnIndex(" id" )
19+ if (columnId == - 1 ) {
20+ throw IllegalArgumentException (" Column 'id' not found in cursor" )
21+ }
1822 val id = cursor.getLong(columnId)
1923 Log .i(TAG , " id: $id " )
2024
2125 val columnRevisionNumber = cursor.getColumnIndex(" revisionNumber" )
26+ if (columnRevisionNumber == - 1 ) {
27+ throw IllegalArgumentException (" Column 'revisionNumber' not found in cursor" )
28+ }
2229 val revisionNumber = cursor.getInt(columnRevisionNumber)
2330 Log .i(TAG , " revisionNumber: $revisionNumber " )
2431
2532 val columnTitle = cursor.getColumnIndex(" title" )
33+ if (columnTitle == - 1 ) {
34+ throw IllegalArgumentException (" Column 'title' not found in cursor" )
35+ }
2636 val title = cursor.getString(columnTitle)
2737 Log .i(TAG , " title: \" $title \" " )
2838
2939 val columnVideoFormat = cursor.getColumnIndex(" videoFormat" )
40+ if (columnVideoFormat == - 1 ) {
41+ throw IllegalArgumentException (" Column 'videoFormat' not found in cursor" )
42+ }
3043 val videoFormatAsString = cursor.getString(columnVideoFormat)
3144 Log .i(TAG , " videoFormatAsString: $videoFormatAsString " )
32- val videoFormat = VideoFormat .valueOf(videoFormatAsString)
45+ val videoFormat = try {
46+ VideoFormat .valueOf(videoFormatAsString)
47+ } catch (e: IllegalArgumentException ) {
48+ Log .e(TAG , " Invalid video format: $videoFormatAsString " , e)
49+ throw IllegalArgumentException (" Invalid video format: $videoFormatAsString " , e)
50+ }
3351 Log .i(TAG , " videoFormat: $videoFormat " )
34-
3552 val video = VideoGson ()
3653 video.id = id
3754 video.revisionNumber = revisionNumber
3855 video.title = title
3956 video.videoFormat = videoFormat
40-
4157 return video
4258 }
4359}
0 commit comments