gnodet-bot commented on code in PR #29574:
URL: https://github.com/apache/camel/pull/29574#discussion_r4527847627
##########
components/camel-http/src/test/java/org/apache/camel/component/http/BaseHttpTest.java:
##########
@@ -56,4 +58,16 @@ protected void assertBody(String body) {
protected String getExpectedContent() {
return "camel rocks!";
}
+
+ /**
+ * Closes the servers without waiting for their open (keep-alive)
connections: the graceful close of an
+ * {@link HttpServer} waits up to 5 seconds for them to terminate.
+ */
+ protected static AutoCloseable closeImmediately(HttpServer... servers) {
+ return () -> {
+ for (HttpServer server : servers) {
+ server.close(CloseMode.IMMEDIATE);
+ }
+ };
+ }
Review Comment:
The old `IOHelper.close()` was null-safe (`if (closeable != null)` guard
before closing). This new helper iterates the varargs and calls
`server.close(CloseMode.IMMEDIATE)` without a null check.
`HttpOAuth2RedirectTokenLeakTest.cleanupResources()` passes three server
fields directly:
```java
closeImmediately(localServer, differentHostRedirectTarget,
differentPortRedirectTarget).close()
```
If `setupResources()` throws after initializing the first server but before
the second or third, the remaining fields are `null` — the cleanup call will
NPE, masking the original setup failure.
```suggestion
protected static AutoCloseable closeImmediately(HttpServer... servers) {
return () -> {
for (HttpServer server : servers) {
if (server != null) {
server.close(CloseMode.IMMEDIATE);
}
}
};
}
```
--
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]