ResultSet.size() and Database.getCount() don't match on start up

When I start up my android application, I try to get all of the existing documents from my database. I know for fact that they all exist, since later on in the application I see so using the same exact query. However, on start up, when I try executing the following code, I get no documents from my ResultSet:

private void findDocuments(){
        Query query = QueryBuilder
              "english word"),
              "swedish word"))
        try {
            ResultSet resultSet = query.execute();
            System.out.println(resultSet.allResults().isEmpty() + "---------" + resultSet.allResults().size()); // this prints statement says prints TRUE and 0 
            if(MainActivity.database.getCount() == 0){ //the count is NOT 0 here
                Log.d("DEBUG", "DB is empty");
            } else {
                List<Result> documents = resultSet.allResults();
                Log.d("DEBUG", "DB is NOT empty" + documents.size());// size is 0 here...
                for(Result result: resultSet){//never enters this!
                    Log.d("DEBUG", result.getString(0));
        } catch (CouchbaseLiteException e) {

The only thing that I am doing different in my later Activity is that I just create and save a new mutable document and then call the same query as above, which then actually displays all of the documents.

What am I doing wrong?

That’s unexpected … it might be a race condition in CBL. Could you file a bug report, please?

Once you call resultSet.allResults().isEmpty() the result set becomes null… Try removing that log statement.

 * Return List of Results. List is unmodifiable and only supports
 * int get(int index), int size(), boolean isEmpty() and Iterator<Result> iterator() methods.
 * Once called allResults(), next() method return null. Don't call next() and allResults()
 * together.
 * @return List of Results

from the documentation of allResults()

1 Like