gnodet opened a new pull request, #31153: URL: https://github.com/apache/camel/pull/31153
## Summary Close the `ValidatorFactory` built by the endpoint when the producer stops to fix a resource leak. ## Root Cause `BeanValidatorEndpoint.createProducer()` calls `ValidatorFactories.buildValidatorFactory()` when no user-supplied `ValidatorFactory` is configured. `ValidatorFactory` implements `AutoCloseable`, but neither `BeanValidatorEndpoint` nor `BeanValidatorProducer` had a `doStop()` override, so the factory was never closed. Each route start created a new, leaked factory. ## Fix - Added an `ownedValidatorFactory` flag to `BeanValidatorProducer`. The endpoint sets it to `true` only when it builds the factory itself. - Added `doStop()` to `BeanValidatorProducer` that calls `validatorFactory.close()` iff the producer owns the factory. - User-supplied factories (set via `validatorFactory=` URI parameter or `setValidatorFactory()`) are intentionally left untouched — the caller owns their lifecycle. ## Tests `ValidatorFactoryLeakTest` covers both paths: 1. `producerOwnsAndClosesBuiltFactory` — asserts `ownedValidatorFactory = true` and that `close()` is called on the spy when the producer stops. 2. `producerDoesNotCloseUserSuppliedFactory` — asserts `ownedValidatorFactory = false` and that `close()` is **never** called on a mock user-supplied factory. --- _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
