close HTTPClient when running with JDK21 or newer (#70)
The Java HTTP client implements AutoCloseable since JDK 21. Closing the client ensures that asynchronous operations and streams are properly terminated. As we support Java 11, we add any old school "finally" wrapper and conditionally close the client when running on a modern platform.
This commit is contained in:
parent
62f2249a4d
commit
52876ef3a4
@ -6,6 +6,7 @@
|
||||
### Improvements
|
||||
* Parse timestamps as `ZonedDateTime` instead of `String` representation
|
||||
* Remove redundant `java.base` requirement from _module-info.java_ (#69)
|
||||
* Close Java HTTP Client when running on Java 21 or later (#70)
|
||||
|
||||
### Dependencies
|
||||
* Updated Jackson to 2.16.0
|
||||
|
@ -363,6 +363,15 @@ public final class RequestHelper implements Serializable {
|
||||
}
|
||||
} catch (CompletionException e) {
|
||||
throw new ConnectionException(Error.CONNECTION, e.getCause());
|
||||
} finally {
|
||||
if (client instanceof AutoCloseable) {
|
||||
// Close the client, which is supported since JDK21.
|
||||
try {
|
||||
((AutoCloseable) client).close();
|
||||
} catch (Exception ignored) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user