Skip to content

Commit

Permalink
[POOL-419] Fix for POOL-419. Make sure that the state of the pooled o…
Browse files Browse the repository at this point in the history
…bject is not invalid before returning back to the pool.
  • Loading branch information
Raju Kumar Gupta committed Feb 4, 2025
1 parent 0d850cf commit 702cdb8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 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,20 @@ public void returnObject(final T obj) {
}
} else {

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

if (getLifo()) {
idleObjects.addFirst(p);
} else {
idleObjects.addLast(p);
if(p.getState() != PooledObjectState.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 702cdb8

Please sign in to comment.