greenrobot/greenDAO · error · DaoException
This operation only works with cached lazy lists
Error message
This operation only works with cached lazy lists
What it means
greenDAO's LazyList can operate in two modes: with an eagerly-loaded entity cache (entities != null) or fully lazy, backed only by the cursor. Operations like loadRemaining() and subList() require random access to already-loaded entities, so they throw this DaoException when the list was created without caching. The check is a guard in LazyList.checkCached() protecting operations that cannot be satisfied lazily.
Solutions
- Use the cached list: call query.list() (or lazyList() only when you truly stream via iterator) instead of calling subList/loadRemaining on the lazy list.
- If you need partial loading with caching, iterate with get()/peek() on the LazyList instead of subList().
- Copy needed items into a plain ArrayList by iterating the LazyList, then use subList on that copy.
Example fix
// before LazyList<User> lazy = query.listLazy(); List<User> page = lazy.subList(10, 20); // DaoException // after List<User> all = query.list(); List<User> page = all.subList(10, 20);
Defensive patterns
Strategy: fallback
Validate before calling
LazyList<User> l = query.listLazyUncached(); boolean ok = !(needsSubList || needsLoadRemaining); // avoid these ops on uncached lazy lists
Try / catch
try { page = lazyList.subList(from, to); } catch (DaoException e) { page = query.list().subList(from, to); } Prevention
- Use query.list() when you need List operations (subList, random access).
- Reserve listLazy()/listLazyUncached() for iteration/streaming only.
- Read the LazyList javadoc: subList/loadRemaining require the cached variant.
When it happens
Trigger: Calling loadRemaining() or subList() on a LazyList obtained from a query that was not built with caching — i.e. Query.forCurrentThread(...)/lazyList() where the query does not use setForThread/CACHED variant (entities == null).
Common situations: Developers grab lazyList() for memory efficiency, then call subList() or loadRemaining() expecting List semantics; it fails because the lazy list never materializes entities into the backing array.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- No entity found for query
- Property '
- Expected unique result, but count was
- Cannot delete entity, key is null
- Entity does not exist in the database anymore
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/118b1fce7c34fa51.
Report an issue: GitHub.
Appendix: source
Thrown at DaoCore/src/main/java/org/greenrobot/greendao/query/LazyList.java:162
if (size == 0) {
cursor.close();
}
lock = new ReentrantLock();
}
/** Loads the remaining entities (if any) that were not loaded before. Applies to cached lazy lists only. */
public void loadRemaining() {
checkCached();
int size = entities.size();
for (int i = 0; i < size; i++) {
get(i);
}
}
protected void checkCached() {
if (entities == null) {
throw new DaoException("This operation only works with cached lazy lists");
}
}
/** Like get but does not load the entity if it was not loaded before. */
public E peek(int location) {
if (entities != null) {
return entities.get(location);
} else {
return null;
}
}
@Override
/** Closes the underlying cursor: do not try to get entities not loaded (using get) before. */
public void close() {
cursor.close();
}
View on GitHub (pinned to 0bbb338e17)