Skip to content

Commit

Permalink
[POOL-419] Fix for POOL-419. Before adding the returned object to the…
Browse files Browse the repository at this point in the history
… pool, we must check whether it is already deallocated.
  • Loading branch information
Raju Kumar Gupta committed Feb 3, 2025
1 parent 0c2961f commit 6201994
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/org/apache/commons/pool3/impl/GenericObjectPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1092,16 +1092,19 @@ public void returnObject(final T obj) {
}
} else {

synchronized (p) {
if(p.getState() != PooledObjectState.INVALID) {
if (getLifo()) {
idleObjects.addFirst(p);
} else {
idleObjects.addLast(p);
}
}
if (!p.deallocate()) {
throw new IllegalStateException(
"Object has already been returned to this pool or is invalid");
}

if (getLifo()) {
idleObjects.addFirst(p);
} else {
idleObjects.addLast(p);
}



if (isClosed()) {
// Pool closed while object was being added to idle objects.
// Make sure the returned object is destroyed rather than left
Expand Down

0 comments on commit 6201994

Please sign in to comment.