commons-pool icon indicating copy to clipboard operation
commons-pool copied to clipboard

[Pool-425] [Pool-426] GenericObjectPool addObject does not respect maxIdle

Open rajucomp opened this issue 4 weeks ago • 1 comments

Thanks for your contribution to Apache Commons! Your help is appreciated!

Before you push a pull request, review this list:

  • [x] Read the contribution guidelines for this project.
  • [x] Read the ASF Generative Tooling Guidance if you use Artificial Intelligence (AI).
  • [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute?
  • [x] Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
  • [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.

Problem/Bug Description

When the pool's addObject() method is called to pre-load the pool with idle objects, the current implementation only validates against maxTotal (the maximum total number of objects that can exist in the pool, including both active and idle objects) to prevent exceeding the configured maximum. However, it does not validate against maxIdle (the maximum number of idle objects allowed in the pool).

This validation gap can result in the pool creating more idle objects than the configured maxIdle limit allows, which violates the pool's configuration contract.

Fix

The fix ensures both maxTotal and maxIdle values are properly compared, and the pool uses the minimum of these two values as the effective limit when deciding whether to add new objects. This ensures the pool respects whichever limit is lower and prevents violating either configuration constraint.

Related JIRA Issue

This fix addresses POOL-425: GenericObjectPool addObject does not respect maxIdle


Checklist

  • [x] Bug fix properly validates against both maxTotal and maxIdle
  • [x] Unit tests added for single-threaded scenarios
  • [x] Concurrent tests added for multi-threaded scenarios
  • [x] All existing tests pass
  • [x] Code follows project conventions and style
  • [x] No breaking changes to public API

rajucomp avatar Dec 14 '25 19:12 rajucomp