[ 
https://issues.apache.org/jira/browse/CB-12326?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15880381#comment-15880381
 ] 

ASF GitHub Bot commented on CB-12326:
-------------------------------------

Github user mad-nuts commented on the issue:

    https://github.com/apache/cordova-plugin-contacts/pull/146
  
    
    I've tried for hours to reproduce the error, but the app just won't crash 
anymore.
    Something must have changed since then and I don't know what it is...
    
    
    Despite the fact, that the app won't crash anymore, the code is still buggy 
and should be fixed some day.
    
    **Here is what had happened in detail, maybe it is useful nevertheless:**
    
    Executing `ContactAccessorSdk5.search` with one or more of the following 
fields caused the crash:
    
    ```
    - navigator.contacts.fieldType.phoneNumbers
      - phoneQuery
        - CommonDataKinds.Phone.LABEL
    - navigator.contacts.fieldType.emails
      - emailQuery
        - CommonDataKinds.Email.LABEL
    - navigator.contacts.fieldType.postalCode
      - addressQuery
        - CommonDataKinds.StructuredPostal.LABEL
    - navigator.contacts.fieldType.organizations
      - organizationQuery
        - CommonDataKinds.Organization.LABEL
    - navigator.contacts.fieldType.urls
      - websiteQuery
        - CommonDataKinds.Website.LABEL
    ```
    
    - `ContactAccessorSdk5.search` is called with the `JSONArray fields` 
containing one / some / all fields of the above
    - the contentResolver projection `columnsToFetch` is created by adding the 
required columns for each passed field (`columnsToFetch.add(...)`)
      - but without adding the columns for `CommonDataKinds.[...].LABEL` to 
`columnsToFetch`
    - `columnsToFetch `is fed to 
`mApp.getActivity().getContentResolver().query(...)`, resulting in Cursor `c`
      - at this state the cursor is already missing the later required `LABEL` 
columns
    - `populateContactArray(limit, populate, c);` is called
    - within the `while` loop query methods are executed to fetch the required 
fields from the cursor.
      - in those query methods `getColumnIndex` is called to retrieve the none 
existing `LABEL` column, returning `-1`
      - `cursor.getString(-1)` is called
        - returns nullable now, which is fine
        - threw an `java.lang.IllegalStateException` back then
    
    `getContactById` is using `populateContactArray `too, but should be fine 
for now, because "null" is passed as the projection param, which returns a 
cursor, pointing to all columns.


> Crash on Android: CommonDataKinds.*.LABEL
> -----------------------------------------
>
>                 Key: CB-12326
>                 URL: https://issues.apache.org/jira/browse/CB-12326
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Contacts
>         Environment: Android: Samsung Galaxy S6
>            Reporter: Andreas
>            Priority: Critical
>              Labels: Android, crash, reproduced
>
> The ContactAccessorSdk5 is missing the "LABEL" CommonDataKinds column 
> definition for multple Cursors, causing the "search" function to crash.
> {code:title=is|borderStyle=solid}
> if (isRequired("emails", populate)) {
>             columnsToFetch.add(CommonDataKinds.Email._ID);
>             columnsToFetch.add(CommonDataKinds.Email.DATA);
>             columnsToFetch.add(CommonDataKinds.Email.TYPE);
>         }
> {code}
> {code:title=should be|borderStyle=solid}
> if (isRequired("emails", populate)) {
>             columnsToFetch.add(CommonDataKinds.Email._ID);
>             columnsToFetch.add(CommonDataKinds.Email.DATA);
>             columnsToFetch.add(CommonDataKinds.Email.TYPE);
>             columnsToFetch.add(CommonDataKinds.Email.LABEL);
>         }
> {code}
> missing columns are:
> - CommonDataKinds.Phone.LABEL
> - CommonDataKinds.Email.LABEL
> - CommonDataKinds.StructuredPostal.LABEL
> - CommonDataKinds.Organization.LABEL
> - CommonDataKinds.Website.LABEL
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime: 
> java.lang.IllegalStateException: Couldn't read row 174, col -1 from 
> CursorWindow.  Make sure the Cursor is initialized correctly before accessing 
> data from it.
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> android.database.CursorWindow.nativeGetString(Native Method)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> android.database.CursorWindow.getString(CursorWindow.java:451)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> android.database.CursorWrapper.getString(CursorWrapper.java:137)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> org.apache.cordova.contacts.ContactAccessorSdk5.emailQuery(ContactAccessorSdk5.java:900)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> org.apache.cordova.contacts.ContactAccessorSdk5.populateContactArray(ContactAccessorSdk5.java:428)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> org.apache.cordova.contacts.ContactAccessorSdk5.search(ContactAccessorSdk5.java:287)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> org.apache.cordova.contacts.ContactManager$3.run(ContactManager.java:209)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
> 01-06 13:43:03.871  7333  7527 E AndroidRuntime:        at 
> java.lang.Thread.run(Thread.java:818)



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to