Skip to content

Conversation

@rajucomp
Copy link

@rajucomp rajucomp commented Dec 14, 2025

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

Before you push a pull request, review this list:

  • Read the contribution guidelines for this project.
  • 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?
  • Run a successful build using the default Maven goal with mvn; that's mvn on the command line by itself.
  • 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.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • 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

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

@rajucomp
Copy link
Author

rajucomp commented Dec 14, 2025

@garydgregory @psteitz Requesting critical review for the fix for POOL-425. Thanks!

@rajucomp rajucomp changed the title [Pool-425] GenericObjectPool addObject does not respect maxIdle [Pool-425] [Pool-426] GenericObjectPool addObject does not respect maxIdle Dec 14, 2025
Comment on lines +516 to +520
int localMaxIdle = getMaxIdle();
if (localMaxIdle < 0) {
localMaxIdle = Integer.MAX_VALUE;
}
final int maxCapacity = Math.min(localMaxTotal, localMaxIdle);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause issues if maxIdle is set to zero, making it impossible to create new objects in the pool.

Since the method is private we can verify it is only used during the borrow, where it is not added to the idle objects, and on addObject, where it is.

the addObject method should be checking the idle object limit isn't being crossed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants