Search code examples
androidstatic-analysiscoverity

Coverity - Explicit null dereferenced (FORWARD_NULL) in contentResolver.delete()


Deleting all the rows from ContentProvider using delete() statement gives the Coverity error.

Explicit null dereferenced (FORWARD_NULL)
Passing null pointer selection to delete, which dereferences it.

String selection = null;
String[] selectionArgs = null;

mContentResolver.delete(MyContentProvider.MY_CONTENT_URI, selection, selectionArgs);

Is there any way to fix this Coverity issue ??


Solution

  • According to your code the issue seems right - you forward "null"... Can you post the code of your ContentResolver Implementation?

    To remove the warning you may try to use:

    String selection = "";
    String[] selectionArgs = new String[0];
    

    As you may see in the source code the selection (at least) for logging is set to:

    selection != null ? selection : "",