gnodet opened a new pull request, #22130: URL: https://github.com/apache/camel/pull/22130
## Summary Deprecate the following methods on `AvailablePortFinder` (in both junit5 and junit6 modules): - `getNextAvailable()` - `getNextRandomAvailable()` - `getNextAvailable(int, int)` - `getSpecificPort()` - `probePort(int)` ### Why `getNextAvailable()` creates a `Port`, immediately closes it (releasing it from the internal tracking map), and returns the raw `int`. This creates a TOCTOU race condition — another thread or process can grab the port between probing and actual use. ### Replacement Use `AvailablePortFinder.find()` which returns a `Port` object that: - Stays reserved in the JVM-wide `portMapping` until released - Implements `@RegisterExtension` for automatic lifecycle management - Implements `AutoCloseable` for try-with-resources usage - Has `toString()` returning the port number (works with string concatenation) - Has `getPort()` for int conversion ```java // Before (deprecated - race condition) int port = AvailablePortFinder.getNextAvailable(); // After (recommended - as JUnit extension) @RegisterExtension static AvailablePortFinder.Port port = AvailablePortFinder.find(); ``` -- 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]
