From 69e4c5002f57252b37330d4323ca57a7ffb62488 Mon Sep 17 00:00:00 2001 From: sebr72 Date: Thu, 25 Apr 2024 11:35:44 +0200 Subject: [PATCH] Stop using finalize with autocloseable. Free resources on close. --- .../java/org/mapfish/print/http/HttpRequestFetcher.java | 4 +++- .../mapfish/print/http/MfClientHttpRequestFactoryImpl.java | 6 ------ .../main/java/org/mapfish/print/map/tiled/CoverageTask.java | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java index 813a08052e..57b723f584 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -127,7 +127,9 @@ public void close() { try { this.body.close(); } catch (IOException e) { - // ignored + LOGGER.warn("Failed to close body", e); + } finally { + this.body = null; } } } diff --git a/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java b/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java index ca42415a04..9407c35e0e 100644 --- a/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java +++ b/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java @@ -229,12 +229,6 @@ public String getStatusText() { return this.response.getStatusLine().getReasonPhrase(); } - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - @Override public void close() { try { diff --git a/core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java b/core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java index 4093f58ff5..6e8667ca2b 100644 --- a/core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java +++ b/core/src/main/java/org/mapfish/print/map/tiled/CoverageTask.java @@ -228,7 +228,7 @@ protected Tile compute() { TilePreparationTask.class.getName() + ".read." + StatsUtils.quotePart(this.tileRequest.getURI().getHost()); - LOGGER.debug("\n\t{} -- {}", this.tileRequest.getMethod(), this.tileRequest.getURI()); + LOGGER.debug("{} -- {}", this.tileRequest.getMethod(), this.tileRequest.getURI()); final Timer.Context timerDownload = this.registry.timer(baseMetricName).time(); try (ClientHttpResponse response = this.tileRequest.execute()) { final HttpStatus statusCode = response.getStatusCode();