title: kotlin function returning null
body: <p>I am trying some android development with kotlin. In my case I want to overwrite: ContentProvider where I have to overwrite the function "query".
  "query" returns "Cursor" type. However, when I create the Cursor instance in the function with database.query I get back a "Cursor?" type. So I can only return Cursor if it is not null, but what do I do if it is null?</p>
  
  <p>This is what it basically looks like:</p>
  
  <pre><code>override fun query(uri: Uri, projection: Array&lt;out String&gt;?, selection: String?, selectionArgs: Array&lt;out String&gt;?, sortOrder: String?): Cursor {
  
      val cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder)
              // make sure that potential listeners are getting notified
              cursor?.setNotificationUri(getContext()?.getContentResolver(), uri)
  
              if(cursor != null)
                  return cursor
              else
                  // what to do here?
  </code></pre>
  
  <p>Any Ideas how to solve that?</p>
  
  <p>Thanks,
  Sven</p>
  
  <p><strong>UPDATE</strong>
  First of all thanks for the answers.</p>
  
  <p><em>Annotation</em> seems not to work in my case as I can only access the compiled code and I dont get the option to annotate the source. Maybe I am missing something here.</p>
  
  <p><em>Implementing my own cursor</em> Seems like overkill especially if I have to do it every time that problem occurs.</p>
  
  <p>So it seems my only option is to return cursor!! But I dont know how exactly to do it. My code is a bit more complicated than in my example, I missed a when statement. This is an updated version:</p>
  
  <pre><code>override fun query(uri: Uri, projection: Array&lt;out String&gt;?, selection: String?, selectionArgs: Array&lt;out String&gt;?, sortOrder: String?): Cursor {
  
      val cursor = ??? //how to initialize cursor somehow?
      val db = database.getWritableDatabase()
  
      if(db != null) {
          val cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder)
                  // make sure that potential listeners are getting notified
                  cursor?.setNotificationUri(getContext()?.getContentResolver(), uri)
  
                  if(cursor != null)
                      return cursor
       }
  
      // return what here? cursor does not exist
  }
  </code></pre>
  
  <p>Do I really have to implement my own cursor and clutter my code with useless "throw UnsupportedExceptions"?</p>