{"record":{"id":"17f4df749af32e98","repo":"greenrobot/greenDAO","slug":"loading-of-entity-failed-null-at-position","errorCode":null,"errorMessage":"Loading of entity failed (null) at position ","messagePattern":"Loading of entity failed \\(null\\) at position ","errorType":"exception","errorClass":"DaoException","httpStatus":null,"severity":"error","filePath":"DaoCore/src/main/java/org/greenrobot/greendao/query/LazyList.java","lineNumber":270,"sourceCode":"        } else {\n            lock.lock();\n            try {\n                return loadEntity(location);\n            } finally {\n                lock.unlock();\n            }\n        }\n    }\n\n    /** Lock must be locked when entering this method. */\n    protected E loadEntity(int location) {\n        boolean ok = cursor.moveToPosition(location);\n        if(!ok) {\n            throw new DaoException(\"Could not move to cursor location \" + location);\n        }\n        E entity = daoAccess.loadCurrent(cursor, 0, true);\n        if (entity == null) {\n            throw new DaoException(\"Loading of entity failed (null) at position \" + location);\n        }\n        return entity;\n    }\n\n    @Override\n    public int indexOf(Object object) {\n        loadRemaining();\n        return entities.indexOf(object);\n    }\n\n    @Override\n    public boolean isEmpty() {\n        return size == 0;\n    }\n\n    @Override\n    public Iterator<E> iterator() {\n        return new LazyIterator(0, false);","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoCore/src/main/java/org/greenrobot/greendao/query/LazyList.java#L252-L288","documentation":"After moving the cursor to the requested row, LazyList.loadEntity() calls daoAccess.loadCurrent(cursor, 0, true); if that returns null the row could not be mapped to an entity and a DaoException is thrown. loadCurrent returning null for a lazily-loaded list means the cursor row was invalid or the row failed entity creation.","triggerScenarios":"LazyList.get(index) where cursor.moveToPosition succeeded but daoAccess.loadCurrent returned null at that position — e.g. the cursor was exhausted/invalidated by concurrent access or the row's data no longer matches the entity mapping.","commonSituations":"Concurrent modification of the database while iterating a LazyList (rows deleted between moveToPosition and loadCurrent), or sharing one query/LazyList across threads without forCurrentThread().","solutions":["Run queries on a single thread or obtain a thread-local copy with query.forCurrentThread().","Re-execute the query (rebuild the LazyList) if the database may have changed.","Wrap in try-catch for DaoException and fall back to a fresh query.list().","Avoid holding a LazyList across transactions that delete rows it references."],"exampleFix":"// before\nLazyList<User> users = query.listLazy(); // reused across threads\nUser u = users.get(5); // intermittent DaoException\n// after\nQuery<User> threadQuery = query.forCurrentThread();\nList<User> users = threadQuery.list();\nif (users.size() > 5) { User u = users.get(5); }","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { u = lazyList.get(i); } catch (DaoException e) { u = query.forCurrentThread().list().get(i); }","preventionTips":["Never share a LazyList or its query across threads; use forCurrentThread().","Avoid holding a LazyList open across write transactions.","Materialize with list() if the data set is small and may change."],"tags":["greendao","cursor","concurrency","android"],"backgroundTag":"entity-not-found","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}