{"record":{"id":"aee1badd807a36d5","repo":"PhilJay/MPAndroidChart","slug":"the-object-passed-is-already-stored-in-this-pool","errorCode":null,"errorMessage":"The object passed is already stored in this pool!","messagePattern":"The object passed is already stored in this pool!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"MPChartLib/src/main/java/com/github/mikephil/charting/utils/ObjectPool.java","lineNumber":135,"sourceCode":"        }\n\n        T result = (T)objects[this.objectsPointer];\n        result.currentOwnerId = Poolable.NO_OWNER;\n        this.objectsPointer--;\n\n        return result;\n    }\n\n    /**\n     * Recycle an instance of Poolable that this pool is capable of generating.\n     * The T instance passed must not already exist inside this or any other ObjectPool instance.\n     *\n     * @param object An object of type T to recycle\n     */\n    public synchronized void recycle(T object){\n        if(object.currentOwnerId != Poolable.NO_OWNER){\n            if(object.currentOwnerId == this.poolId){\n                throw new IllegalArgumentException(\"The object passed is already stored in this pool!\");\n            }else {\n                throw new IllegalArgumentException(\"The object to recycle already belongs to poolId \" + object.currentOwnerId + \".  Object cannot belong to two different pool instances simultaneously!\");\n            }\n        }\n\n        this.objectsPointer++;\n        if(this.objectsPointer >= objects.length){\n            this.resizePool();\n        }\n\n        object.currentOwnerId = this.poolId;\n        objects[this.objectsPointer] = object;\n\n    }\n\n    /**\n     * Recycle a List of Poolables that this pool is capable of generating.\n     * The T instances passed must not already exist inside this or any other ObjectPool instance.","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/PhilJay/MPAndroidChart/blob/9c7275a0596a7ac0e50ca566e680f7f9d73607af/MPChartLib/src/main/java/com/github/mikephil/charting/utils/ObjectPool.java#L117-L153","documentation":"Thrown by ObjectPool.recycle(T) when the object's currentOwnerId equals this pool's id, meaning it was already returned to this pool. Each Poolable tracks its owner; recycling the same instance twice into the same pool would duplicate it. This is the branch where object.currentOwnerId == this.poolId.","triggerScenarios":"Calling pool.recycle(obj) twice for the same instance without re-acquiring it in between. Recycling an object still referenced by a list that was already bulk-recycled. Losing track of ownership in a manual object-lifecycle implementation.","commonSituations":"Custom view/chart recycling logic that returns objects on both a normal and an error path; recycling objects held in a cached collection that is also recycled; double-free bugs from copy-paste.","solutions":["Acquire a fresh object from the pool before recycling the same reference again.","After recycle(obj), null out the local reference so it cannot be recycled twice.","Use recycle(List) once over a batch rather than recycling individual duplicates.","Add logging of object.currentOwnerId around recycle() to find double-return paths."],"exampleFix":"// before\npool.recycle(obj);\n// ...later, same ref still in scope\npool.recycle(obj); // throws: already in this pool\n\n// after\npool.recycle(obj);\nobj = null;\n// next use:\nobj = pool.get();","handlingStrategy":"validation","validationCode":"if (object.currentOwnerId == Poolable.NO_OWNER) {\n    pool.recycle(object);\n} else {\n    Log.w(TAG, \"Object not eligible for recycle, owner=\" + object.currentOwnerId);\n}","typeGuard":"boolean isRecyclableHere(Poolable o, ObjectPool pool) {\n    return o.currentOwnerId == Poolable.NO_OWNER;\n}","tryCatchPattern":null,"preventionTips":["Null out local references immediately after recycle().","Acquire a fresh object before recycling the same reference again.","Avoid recycling the same object on both success and error paths."],"tags":["object-pool","recycle","double-free","ownership"],"backgroundTag":null,"analyzedSha":"9c7275a0596a7ac0e50ca566e680f7f9d73607af","analyzedAt":"2026-08-14T00:17:56.136Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}