greenrobot/greenDAO · error · DaoException

This operation did not yet complete

Error message

This operation did not yet complete

What it means

AsyncOperation.getDuration() computes timeCompleted - timeStarted, but the operation timestamps are only set when the async executor finishes the operation. If the operation has not completed yet, timeCompleted is 0 and the method throws this DaoException instead of returning a bogus negative duration.

Solutions

  1. Wait for completion before asking for the duration: call operation.waitForCompletion() or check operation.isOperationCompleted() first.
  2. Only compute timing inside the AsyncOperationListener's onOperationCompleted callback.
  3. If you need elapsed time regardless, track System.currentTimeMillis() yourself around the enqueue call.

Example fix

// before
AsyncOperation op = asyncSession.insert(entity);
long duration = op.getDuration(); // throws if not done
// after
AsyncOperation op = asyncSession.insert(entity);
op.waitForCompletion();
long duration = op.getDuration();
Defensive patterns

Strategy: validation

Validate before calling

if (!op.isOperationCompleted()) {
    throw new IllegalStateException("wait for the async operation before calling getDuration()");
}

Try / catch

try {
    long d = op.getDuration();
} catch (DaoException e) {
    // op not completed yet: wait or skip timing
    op.waitForCompletion();
    long d = op.getDuration();
}

Prevention

When it happens

Trigger: Calling getDuration() on an AsyncOperation object obtained from AsyncSession (e.g. insertAsync/insertInTxAsync return ops or listeners) before the operation has executed on the AsyncOperationExecutor thread — i.e. before isOperationCompleted()/waitForCompletion() returns.

Common situations: Developers query timing right after enqueueing an async insert, or in code that runs concurrently with the operation, e.g. measuring performance immediately after submit instead of in the completion listener.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/717816acd96a6ca7. Report an issue: GitHub.

Appendix: source

Thrown at DaoCore/src/main/java/org/greenrobot/greendao/async/AsyncOperation.java:137

    /**
     * @return true if this operation is mergeable with the given operation. Checks for null, {@link #FLAG_MERGE_TX},
     * and if the database instances match.
     */
    boolean isMergeableWith(AsyncOperation other) {
        return other != null && isMergeTx() && other.isMergeTx() && getDatabase() == other.getDatabase();
    }

    public long getTimeStarted() {
        return timeStarted;
    }

    public long getTimeCompleted() {
        return timeCompleted;
    }

    public long getDuration() {
        if (timeCompleted == 0) {
            throw new DaoException("This operation did not yet complete");
        } else {
            return timeCompleted - timeStarted;
        }
    }

    public boolean isFailed() {
        return throwable != null;
    }

    public boolean isCompleted() {
        return completed;
    }

    /**
     * Waits until the operation is complete. If the thread gets interrupted, any {@link InterruptedException} will be
     * rethrown as a {@link DaoException}.
     *
     * @return Result if any, see {@link #getResult()}

View on GitHub (pinned to 0bbb338e17)