From e9730098f45168c6ba618e35bf941efe14455a48 Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Thu, 12 Jun 2025 00:39:09 -0300 Subject: [PATCH 1/4] Initial apply of OpenReWrite recipe ``` mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \ -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE \ -Drewrite.activeRecipes=org.openrewrite.java.migrate.UpgradeToJava17 \ -Drewrite.exportDatatables=true ``` --- ...nLayerConformanceWithArcGisLayersTest.java | 12 +- geowebcache/azureblob/pom.xml | 6 + .../geowebcache/azure/AzureBlobStoreData.java | 4 +- .../geowebcache/azure/AzureBlobStoreInfo.java | 6 +- .../org/geowebcache/azure/AzureClient.java | 2 +- .../org/geowebcache/azure/DeleteManager.java | 27 +- .../azure/AzureBlobStoreIntegrationTest.java | 2 +- .../azure/AzuriteContainer.java | 3 +- geowebcache/core/pom.xml | 6 + .../ClientStreamAbortedException.java | 2 + .../geowebcache/GeoWebCacheDispatcher.java | 18 +- .../geowebcache/GeoWebCacheEnvironment.java | 4 +- .../org/geowebcache/GeoWebCacheException.java | 3 + .../geowebcache/GeoWebCacheExtensions.java | 12 +- .../UncheckedGeoWebCacheException.java | 2 + .../org/geowebcache/config/BlobStoreInfo.java | 2 + .../config/ConfigurationException.java | 2 + .../geowebcache/config/FileBlobStoreInfo.java | 2 + .../config/ListenerCollection.java | 11 +- .../geowebcache/config/XMLConfiguration.java | 40 +-- .../org/geowebcache/config/XMLGridSet.java | 2 + .../org/geowebcache/config/XMLGridSubset.java | 2 + .../org/geowebcache/config/XMLOldGrid.java | 2 + .../config/meta/ServiceContact.java | 2 + .../config/meta/ServiceInformation.java | 2 + .../config/meta/ServiceProvider.java | 2 + .../main/java/org/geowebcache/demo/Demo.java | 111 +++--- .../filter/parameters/CaseNormalizer.java | 2 + .../CaseNormalizingParameterFilter.java | 2 + .../parameters/FloatParameterFilter.java | 2 + .../parameters/IntegerParameterFilter.java | 2 + .../filter/parameters/ParameterException.java | 2 + .../filter/parameters/ParameterFilter.java | 2 + .../parameters/RegexParameterFilter.java | 2 + .../parameters/StringParameterFilter.java | 2 + .../filter/request/BlankTileException.java | 2 + .../filter/request/CircularExtentFilter.java | 2 + .../filter/request/FileRasterFilter.java | 2 + .../filter/request/GreenTileException.java | 2 + .../filter/request/RasterFilter.java | 2 + .../filter/request/RequestFilter.java | 2 + .../request/RequestFilterException.java | 2 + .../filter/request/WMSRasterFilter.java | 2 + .../org/geowebcache/grid/BoundingBox.java | 5 +- .../grid/BoundingBoxException.java | 2 + .../main/java/org/geowebcache/grid/Grid.java | 2 + .../grid/OutsideCoverageException.java | 2 + .../org/geowebcache/io/ByteArrayResource.java | 3 +- .../geowebcache/io/GeoWebCacheXStream.java | 8 +- .../geowebcache/layer/BadTileException.java | 2 + .../java/org/geowebcache/layer/MetaTile.java | 46 ++- .../org/geowebcache/mime/MimeException.java | 2 + .../java/org/geowebcache/seed/SeedTask.java | 8 +- .../org/geowebcache/seed/SeederException.java | 2 + .../geowebcache/seed/TruncateAllRequest.java | 2 + .../service/HttpErrorCodeException.java | 3 + .../org/geowebcache/service/OWSException.java | 2 + .../java/org/geowebcache/service/Service.java | 3 +- .../geowebcache/service/ServiceException.java | 2 + .../org/geowebcache/storage/BlobStore.java | 3 +- .../storage/BlobStoreAggregator.java | 7 +- .../geowebcache/storage/MetastoreRemover.java | 24 +- .../geowebcache/storage/StorageException.java | 2 + .../org/geowebcache/storage/TileObject.java | 2 + .../storage/TileRangeIterator.java | 4 +- .../storage/UnsuitableStorageException.java | 3 + .../storage/blobstore/file/FileBlobStore.java | 2 +- .../storage/blobstore/file/FilePathUtils.java | 2 +- .../blobstore/memory/CacheConfiguration.java | 2 + .../blobstore/memory/CacheStatistics.java | 2 + .../java/org/geowebcache/util/FileUtils.java | 5 +- .../java/org/geowebcache/util/GWCVars.java | 4 +- .../org/geowebcache/util/ServletUtils.java | 2 +- .../org/geowebcache/util/TMSKeyBuilder.java | 2 +- .../java/org/geowebcache/TestHelpers.java | 8 +- ...tsConfigurationGridsetConformanceTest.java | 10 +- .../config/DefaultingConfigurationTest.java | 3 +- ...ConfigurationBlobStoreConformanceTest.java | 4 +- ...MLConfigurationGridsetConformanceTest.java | 10 +- .../XMLConfigurationLayerConformanceTest.java | 6 +- .../parameters/FloatParameterFilterTest.java | 42 +-- .../IntegerParameterFilterTest.java | 50 +-- .../parameters/ParametersUtilsTest.java | 4 +- .../parameters/RegexParameterFilterTest.java | 109 +++--- .../parameters/StringParameterFilterTest.java | 165 ++++----- .../geowebcache/layer/wms/MetaTileTest.java | 4 +- .../org/geowebcache/util/FileMatchers.java | 40 +-- .../geowebcache/util/MockWMSLayerSource.java | 12 +- .../geowebcache/util/MockWMSSourceHelper.java | 3 +- .../java/org/geowebcache/util/TestUtils.java | 2 +- .../diskquota/bdb/BDBQuotaStore.java | 4 +- .../diskquota/BDBQuotaStoreTest.java | 7 +- .../diskquota/DiskQuotaConfig.java | 2 + .../diskquota/storage/LayerQuota.java | 2 + .../diskquota/storage/PageStats.java | 2 + .../geowebcache/diskquota/storage/Quota.java | 2 + .../diskquota/jdbc/JDBCConfiguration.java | 2 + .../diskquota/jdbc/JDBCQuotaStore.java | 8 +- .../diskquota/jdbc/JDBCQuotaStoreTest.java | 5 +- .../geowebcache/georss/GeoRSSPollTask.java | 8 +- .../org/geowebcache/georss/GeoRSSPoller.java | 3 +- .../geowebcache/service/kml/KMLService.java | 12 +- .../geowebcache/service/kml/KMLSiteMap.java | 12 +- .../mbtiles/layer/MBTilesLayerTest.java | 8 +- .../rest/controller/BlobStoreController.java | 6 +- .../rest/controller/GridSetController.java | 4 +- .../controller/MemoryCacheController.java | 8 +- .../rest/converter/GWCConverter.java | 28 +- .../rest/exception/RestException.java | 2 + .../geowebcache/rest/service/FormService.java | 17 +- .../filter/FilterUpdateControllerTest.java | 11 +- .../rest/service/FormServiceTest.java | 33 +- geowebcache/s3storage/pom.xml | 6 + .../java/org/geowebcache/s3/S3BlobStore.java | 9 +- .../org/geowebcache/s3/S3BlobStoreInfo.java | 6 +- .../main/java/org/geowebcache/s3/S3Ops.java | 18 +- .../s3/streams/BoundedS3KeySupplier.java | 9 +- .../s3/streams/UnboundedS3KeySupplier.java | 2 +- .../AbstractS3BlobStoreIntegrationTest.java | 2 +- .../sqlite/GeoToolsMbtilesUtils.java | 2 +- .../geowebcache/sqlite/MbtilesBlobStore.java | 49 ++- .../org/geowebcache/sqlite/MbtilesInfo.java | 2 + .../sqlite/SqliteConnectionManager.java | 54 ++- .../org/geowebcache/sqlite/SqliteInfo.java | 2 + .../java/org/geowebcache/sqlite/Utils.java | 4 +- .../sqlite/OperationsRestTest.java | 3 +- .../sqlite/SqliteConnectionManagerTest.java | 6 +- .../org/geowebcache/sqlite/SqlitlePerf.java | 64 ++-- geowebcache/swiftblob/pom.xml | 6 + .../org/geowebcache/swift/SwiftBlobStore.java | 8 +- .../geowebcache/swift/SwiftBlobStoreInfo.java | 6 +- .../geowebcache/swift/SwiftDeleteTask.java | 5 +- .../java/org/geowebcache/swift/SwiftTile.java | 2 +- .../geowebcache/swift/SwiftUploadTask.java | 8 +- .../org/geowebcache/jetty/HttpClientRule.java | 2 +- .../jetty/RestIntegrationTest.java | 320 +++++++++--------- .../parameters/NaiveWMSDimensionFilter.java | 8 +- .../io/codec/ImageDecoderImpl.java | 10 +- .../io/codec/ImageEncoderImpl.java | 9 +- .../geowebcache/io/codec/PNGImageEncoder.java | 4 +- .../service/wms/WMSGetCapabilities.java | 6 +- .../geowebcache/service/wms/WMSService.java | 8 +- .../geowebcache/service/wms/WMSTileFuser.java | 3 +- ...esGridSetConfigurationConformanceTest.java | 10 +- .../service/wmts/WMTSGetCapabilities.java | 3 +- .../geowebcache/service/wmts/WMTSService.java | 9 +- .../service/wmts/WMTSRestTest.java | 4 +- 147 files changed, 966 insertions(+), 842 deletions(-) diff --git a/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java b/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java index 5117e5351..3003ed6d8 100644 --- a/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java +++ b/geowebcache/arcgiscache/src/test/java/org/geowebcache/arcgis/layer/XMLConfigurationLayerConformanceWithArcGisLayersTest.java @@ -22,7 +22,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -123,8 +123,8 @@ protected Matcher infoEquals(TileLayer expected) { @Override public boolean matches(Object item) { - return item instanceof ArcGISCacheLayer - && ((ArcGISCacheLayer) item).getBackendTimeout().equals(expected.getBackendTimeout()); + return item instanceof ArcGISCacheLayer agiscl + && agiscl.getBackendTimeout().equals(expected.getBackendTimeout()); } }; } @@ -135,8 +135,8 @@ protected Matcher infoEquals(int expected) { @Override public boolean matches(Object item) { - return item instanceof ArcGISCacheLayer - && ((ArcGISCacheLayer) item).getBackendTimeout().equals(expected); + return item instanceof ArcGISCacheLayer agiscl + && agiscl.getBackendTimeout().equals(expected); } }; } @@ -158,7 +158,7 @@ protected void makeConfigFile() throws Exception { configFile = temp.newFile("geowebcache.xml"); URL source = XMLConfigurationLayerConformanceWithArcGisLayersTest.class.getResource("geowebcache.xml"); - try (Stream lines = Files.lines(Paths.get(source.toURI()))) { + try (Stream lines = Files.lines(Path.of(source.toURI()))) { List replaced = lines.map(line -> { String tilingSchemePath = resourceAsFile("/compactcache/Conf.xml").getAbsolutePath(); diff --git a/geowebcache/azureblob/pom.xml b/geowebcache/azureblob/pom.xml index 6c7fb1d4f..34d97d953 100644 --- a/geowebcache/azureblob/pom.xml +++ b/geowebcache/azureblob/pom.xml @@ -37,6 +37,12 @@ gwc-core ${project.version} + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + com.azure diff --git a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreData.java b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreData.java index b31d44d64..43100db38 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreData.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreData.java @@ -160,9 +160,9 @@ public String getLocation() { String container = this.getContainer(); String prefix = this.getPrefix(); if (prefix == null) { - return String.format("container: %s", container); + return "container: %s".formatted(container); } else { - return String.format("container: %s prefix: %s", container, prefix); + return "container: %s prefix: %s".formatted(container, prefix); } } diff --git a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreInfo.java b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreInfo.java index 43978b636..29428b8a1 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreInfo.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureBlobStoreInfo.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.io.Serial; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; @@ -30,6 +31,7 @@ /** Plain old java object representing the configuration for an Azure blob store. */ public class AzureBlobStoreInfo extends BlobStoreInfo { + @Serial private static final long serialVersionUID = -8068069256598987874L; /** @@ -229,9 +231,9 @@ public String getLocation() { String container = this.getContainer(); String prefix = this.getPrefix(); if (prefix == null) { - return String.format("container: %s", container); + return "container: %s".formatted(container); } else { - return String.format("container: %s prefix: %s", container, prefix); + return "container: %s prefix: %s".formatted(container, prefix); } } diff --git a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java index ee61f68fd..e2ca06ac8 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java @@ -142,7 +142,7 @@ String getServiceURL(AzureBlobStoreData configuration) { // default to account name based location String proto = configuration.isUseHTTPS() ? "https" : "http"; String account = configuration.getAccountName(); - serviceURL = String.format("%s://%s.blob.core.windows.net", proto, account); + serviceURL = "%s://%s.blob.core.windows.net".formatted(proto, account); } return serviceURL; } diff --git a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java index 586869572..3f313214f 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java @@ -118,8 +118,7 @@ public Long deleteParallel(List keys) throws StorageException { public boolean scheduleAsyncDelete(final String prefix) throws StorageException { final long timestamp = currentTimeSeconds(); - String msg = String.format( - "Issuing bulk delete on '%s/%s' for objects older than %d", + String msg = "Issuing bulk delete on '%s/%s' for objects older than %d".formatted( client.getContainerName(), prefix, timestamp); log.info(msg); @@ -159,8 +158,7 @@ public void issuePendingBulkDeletes() throws StorageException { final String prefix = e.getKey().toString(); final long timestamp = Long.parseLong(e.getValue().toString()); if (log.isLoggable(Level.INFO)) - log.info(String.format( - "Restarting pending bulk delete on '%s/%s':%d", + log.info("Restarting pending bulk delete on '%s/%s':%d".formatted( client.getContainerName(), prefix, timestamp)); if (!asyncDelete(prefix, timestamp)) { deletesToClear.add(prefix); @@ -219,8 +217,7 @@ public Long call() throws Exception { try { checkInterrupted(); if (log.isLoggable(Level.INFO)) - log.info(String.format( - "Running bulk delete on '%s/%s':%d", client.getContainerName(), prefix, timestamp)); + log.info("Running bulk delete on '%s/%s':%d".formatted(client.getContainerName(), prefix, timestamp)); BlobContainerClient container = client.getContainer(); @@ -238,23 +235,20 @@ public Long call() throws Exception { } } } catch (InterruptedException | IllegalStateException e) { - log.info(String.format( - "Azure bulk delete aborted for '%s/%s'. Will resume on next startup.", + log.info("Azure bulk delete aborted for '%s/%s'. Will resume on next startup.".formatted( client.getContainerName(), prefix)); throw e; } catch (RuntimeException e) { log.log( Level.WARNING, - String.format( - "Unknown error performing bulk Azure blobs delete of '%s/%s'", + "Unknown error performing bulk Azure blobs delete of '%s/%s'".formatted( client.getContainerName(), prefix), e); throw e; } if (log.isLoggable(Level.INFO)) - log.info(String.format( - "Finished bulk delete on '%s/%s':%d. %d objects deleted", + log.info("Finished bulk delete on '%s/%s':%d. %d objects deleted".formatted( client.getContainerName(), prefix, timestamp, count)); clearPendingBulkDelete(prefix, timestamp); @@ -286,8 +280,7 @@ private void clearPendingBulkDelete(final String prefix, final long timestamp) t if (timestamp >= storedTimestamp) { client.putProperties(pendingDeletesKey, deletes); } else if (log.isLoggable(Level.INFO)) { - log.info(String.format( - "bulk delete finished but there's a newer one ongoing for container '%s/%s'", + log.info("bulk delete finished but there's a newer one ongoing for container '%s/%s'".formatted( client.getContainerName(), prefix)); } } catch (StorageException e) { @@ -329,8 +322,7 @@ public Long call() throws Exception { try { checkInterrupted(); if (log.isLoggable(Level.FINER)) { - log.finer(String.format( - "Running delete delete on list of items on '%s':%s ... (only the first 100 items listed)", + log.finer("Running delete delete on list of items on '%s':%s ... (only the first 100 items listed)".formatted( client.getContainerName(), keys.subList(0, Math.min(keys.size(), 100)))); } @@ -348,8 +340,7 @@ public Long call() throws Exception { } if (log.isLoggable(Level.INFO)) - log.info(String.format( - "Finished bulk delete on %s, %d objects deleted", client.getContainerName(), count)); + log.info("Finished bulk delete on %s, %d objects deleted".formatted(client.getContainerName(), count)); return count; } diff --git a/geowebcache/azureblob/src/test/java/org/geowebcache/azure/AzureBlobStoreIntegrationTest.java b/geowebcache/azureblob/src/test/java/org/geowebcache/azure/AzureBlobStoreIntegrationTest.java index 6b2dab5d5..c3bafd9d6 100644 --- a/geowebcache/azureblob/src/test/java/org/geowebcache/azure/AzureBlobStoreIntegrationTest.java +++ b/geowebcache/azureblob/src/test/java/org/geowebcache/azure/AzureBlobStoreIntegrationTest.java @@ -539,7 +539,7 @@ private void seed( int max = (int) Math.pow(2, z); for (int x = 0; x < max; x++) { for (int y = 0; y < max; y++) { - log.fine(String.format("seeding %d,%d,%d", x, y, z)); + log.fine("seeding %d,%d,%d".formatted(x, y, z)); put(x, y, z, gridset, formatExtension, parameters); } } diff --git a/geowebcache/azureblob/src/test/java/org/geowebcache/testcontainers/azure/AzuriteContainer.java b/geowebcache/azureblob/src/test/java/org/geowebcache/testcontainers/azure/AzuriteContainer.java index 82466f2ff..5bf3d7a18 100644 --- a/geowebcache/azureblob/src/test/java/org/geowebcache/testcontainers/azure/AzuriteContainer.java +++ b/geowebcache/azureblob/src/test/java/org/geowebcache/testcontainers/azure/AzuriteContainer.java @@ -13,7 +13,6 @@ */ package org.geowebcache.testcontainers.azure; -import static java.lang.String.format; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -145,7 +144,7 @@ public int getBlobsPort() { } public String getBlobServiceUrl() { - return format("http://localhost:%d/%s", getBlobsPort(), getAccountName()); + return "http://localhost:%d/%s".formatted(getBlobsPort(), getAccountName()); } public AzureBlobStoreData getConfiguration(String container) { diff --git a/geowebcache/core/pom.xml b/geowebcache/core/pom.xml index ea5c6781c..97144eb25 100644 --- a/geowebcache/core/pom.xml +++ b/geowebcache/core/pom.xml @@ -105,6 +105,12 @@ org.springframework spring-webmvc + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + org.springframework spring-jdbc diff --git a/geowebcache/core/src/main/java/org/geowebcache/ClientStreamAbortedException.java b/geowebcache/core/src/main/java/org/geowebcache/ClientStreamAbortedException.java index 87046325b..2956d3696 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/ClientStreamAbortedException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/ClientStreamAbortedException.java @@ -14,6 +14,7 @@ package org.geowebcache; import java.io.IOException; +import java.io.Serial; /** * An IOException that means a {@link ServiceStrategy#getDestination(javax.servlet.http.HttpServletResponse) @@ -28,6 +29,7 @@ */ public final class ClientStreamAbortedException extends IOException { + @Serial private static final long serialVersionUID = -812677957232110980L; public ClientStreamAbortedException() { diff --git a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java index c7a7fd99c..4e765fc49 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java +++ b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheDispatcher.java @@ -339,7 +339,7 @@ private boolean isClientStreamAbortedException(Throwable t) { while (current != null && !(current instanceof ClientStreamAbortedException) && !(current instanceof HttpErrorCodeException)) { - if (current instanceof SAXException) current = ((SAXException) current).getException(); + if (current instanceof SAXException exception) current = exception.getException(); else current = current.getCause(); } if (current instanceof ClientStreamAbortedException) { @@ -393,8 +393,8 @@ private void handleServiceRequest(String serviceStr, HttpServletRequest request, if (!layer.isEnabled()) { throw new OWSException(400, "InvalidParameterValue", "LAYERS", "Layer '" + layerName + "' is disabled"); } - if (conv instanceof ConveyorTile) { - ((ConveyorTile) conv).setTileLayer(layer); + if (conv instanceof ConveyorTile tile) { + tile.setTileLayer(layer); } } else { layer = null; @@ -513,8 +513,8 @@ private void appendStorageLocations(StringBuilder str) { str.append("\n"); str.append(""); XMLConfiguration config; - if (mainConfiguration instanceof XMLConfiguration) { - config = (XMLConfiguration) mainConfiguration; + if (mainConfiguration instanceof XMLConfiguration configuration) { + config = configuration; } else { config = GeoWebCacheExtensions.bean(XMLConfiguration.class); } @@ -522,8 +522,8 @@ private void appendStorageLocations(StringBuilder str) { String localStorageLoc; // TODO: Disk Quota location Map blobStoreLocations = new HashMap<>(); - if (storageBroker instanceof DefaultStorageBroker) { - BlobStore bStore = ((DefaultStorageBroker) storageBroker).getBlobStore(); + if (storageBroker instanceof DefaultStorageBroker broker) { + BlobStore bStore = broker.getBlobStore(); if (bStore instanceof CompositeBlobStore) { for (BlobStoreInfo bsConfig : blobStoreAggregator.getBlobStores()) { blobStoreLocations.put(bsConfig.getName(), bsConfig.getLocation()); @@ -584,8 +584,8 @@ private void appendInternalCacheStats(StringBuilder strGlobal) { LOG.fine("Searching for the blobstore used"); } // Getting the BlobStore if present - if (storageBroker instanceof DefaultStorageBroker) { - blobStore = ((DefaultStorageBroker) storageBroker).getBlobStore(); + if (storageBroker instanceof DefaultStorageBroker broker) { + blobStore = broker.getBlobStore(); } // If it is not present, or it is not a memory blobstore, nothing is done diff --git a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java index da94b3d4b..c030205d4 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java +++ b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheEnvironment.java @@ -139,8 +139,8 @@ protected String resolveStringValue(String strVal) throws BeansException { */ @SuppressWarnings("unchecked") public T resolveValue(T value) { - if (value instanceof String) { - return (T) resolveStringValue((String) value); + if (value instanceof String string) { + return (T) resolveStringValue(string); } return value; diff --git a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheException.java b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheException.java index 39eb5aa0c..791ef448b 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheException.java @@ -13,8 +13,11 @@ */ package org.geowebcache; +import java.io.Serial; + public class GeoWebCacheException extends Exception { /** */ + @Serial private static final long serialVersionUID = 5837933971679774371L; public GeoWebCacheException(String msg) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheExtensions.java b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheExtensions.java index 056988ba4..68f5ed641 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheExtensions.java +++ b/geowebcache/core/src/main/java/org/geowebcache/GeoWebCacheExtensions.java @@ -211,13 +211,13 @@ public static void reinitialize(ApplicationContext context) { try { bean.deinitialize(); } catch (Exception e) { - if (bean instanceof BaseConfiguration) { + if (bean instanceof BaseConfiguration configuration) { LOGGER.log( Level.SEVERE, "Error while preparing configuration to reinitialize " - + ((BaseConfiguration) bean).getIdentifier() + + configuration.getIdentifier() + " from " - + ((BaseConfiguration) bean).getLocation(), + + configuration.getLocation(), e); } else { LOGGER.log(Level.SEVERE, "Error while preparing bean to reinitialize " + bean.toString(), e); @@ -228,13 +228,13 @@ public static void reinitialize(ApplicationContext context) { try { bean.reinitialize(); } catch (Exception e) { - if (bean instanceof BaseConfiguration) { + if (bean instanceof BaseConfiguration configuration) { LOGGER.log( Level.SEVERE, "Error while reinitializing configuration " - + ((BaseConfiguration) bean).getIdentifier() + + configuration.getIdentifier() + " from " - + ((BaseConfiguration) bean).getLocation(), + + configuration.getLocation(), e); } else { LOGGER.log(Level.SEVERE, "Error while reinitializing bean " + bean.toString(), e); diff --git a/geowebcache/core/src/main/java/org/geowebcache/UncheckedGeoWebCacheException.java b/geowebcache/core/src/main/java/org/geowebcache/UncheckedGeoWebCacheException.java index 2d6b67025..4095ca97d 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/UncheckedGeoWebCacheException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/UncheckedGeoWebCacheException.java @@ -13,11 +13,13 @@ */ package org.geowebcache; +import java.io.Serial; import java.util.Objects; public class UncheckedGeoWebCacheException extends RuntimeException { /** serialVersionUID */ + @Serial private static final long serialVersionUID = -7981050129260733945L; public UncheckedGeoWebCacheException(GeoWebCacheException cause) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/BlobStoreInfo.java b/geowebcache/core/src/main/java/org/geowebcache/config/BlobStoreInfo.java index 972a4f361..7316ca146 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/BlobStoreInfo.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/BlobStoreInfo.java @@ -13,6 +13,7 @@ */ package org.geowebcache.config; +import java.io.Serial; import java.io.Serializable; import org.geowebcache.layer.TileLayerDispatcher; import org.geowebcache.locks.LockProvider; @@ -38,6 +39,7 @@ */ public abstract class BlobStoreInfo implements Serializable, Cloneable, Info { + @Serial private static final long serialVersionUID = 1L; private String name; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/ConfigurationException.java b/geowebcache/core/src/main/java/org/geowebcache/config/ConfigurationException.java index 7750cdd5e..c3bbca72e 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/ConfigurationException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/ConfigurationException.java @@ -13,6 +13,7 @@ */ package org.geowebcache.config; +import java.io.Serial; import org.geowebcache.GeoWebCacheException; /** @@ -21,6 +22,7 @@ */ public class ConfigurationException extends GeoWebCacheException { + @Serial private static final long serialVersionUID = 1613753249919539845L; public ConfigurationException(String msg) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/FileBlobStoreInfo.java b/geowebcache/core/src/main/java/org/geowebcache/config/FileBlobStoreInfo.java index 44f614eda..a0345ab46 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/FileBlobStoreInfo.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/FileBlobStoreInfo.java @@ -15,6 +15,7 @@ import static com.google.common.base.Preconditions.checkState; +import java.io.Serial; import org.geowebcache.layer.TileLayerDispatcher; import org.geowebcache.locks.LockProvider; import org.geowebcache.storage.BlobStore; @@ -38,6 +39,7 @@ public static enum PathGeneratorType { SLIPPY } + @Serial private static final long serialVersionUID = -6470560864068854508L; private String baseDirectory; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/ListenerCollection.java b/geowebcache/core/src/main/java/org/geowebcache/config/ListenerCollection.java index 7f96fcf8f..6a2e36d95 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/ListenerCollection.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/ListenerCollection.java @@ -62,8 +62,7 @@ public synchronized void safeForEach(HandlerMethod method) throws GeoW return Optional.of(ex); } }) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .collect(Collectors.collectingAndThen(Collectors.toList(), LinkedList::new)); if (!exceptions.isEmpty()) { Iterator it = exceptions.descendingIterator(); @@ -71,10 +70,10 @@ public synchronized void safeForEach(HandlerMethod method) throws GeoW while (it.hasNext()) { ex.addSuppressed(it.next()); } - if (ex instanceof GeoWebCacheException) { - throw (GeoWebCacheException) ex; - } else if (ex instanceof IOException) { - throw (IOException) ex; + if (ex instanceof GeoWebCacheException exception1) { + throw exception1; + } else if (ex instanceof IOException exception) { + throw exception; } else { throw (RuntimeException) ex; } diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java index cc8c52e87..a5d194f7a 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java @@ -247,8 +247,7 @@ public void setDefaultValues(TileLayer layer) { } } - if (layer instanceof WMSLayer) { - WMSLayer wl = (WMSLayer) layer; + if (layer instanceof WMSLayer wl) { URL proxyUrl = null; try { @@ -429,11 +428,11 @@ public static XStream getConfiguredXStreamWithContext( GeoWebCacheExtensions.extensions(XMLConfigurationProvider.class, context); for (XMLConfigurationProvider extension : configExtensions) { // Check if the provider is context dependent - if (extension instanceof ContextualConfigurationProvider + if (extension instanceof ContextualConfigurationProvider provider && // Check if the context is applicable for the provider (providerContext == null - || !((ContextualConfigurationProvider) extension).appliesTo(providerContext))) { + || !provider.appliesTo(providerContext))) { // If so, try the next one continue; } @@ -793,7 +792,7 @@ private static Node applyTransform(Node oldRootNode, String xslFilename) { public void afterPropertiesSet() throws GeoWebCacheException { if (!resourceProvider.hasInput()) { throw new ConfigurationException( - String.format("The configuration resource provider is unable to provide a configuration file")); + "The configuration resource provider is unable to provide a configuration file".formatted()); } if (gridSetBroker == null) { throw new IllegalStateException("GridSetBroker has not been set"); @@ -958,8 +957,7 @@ public synchronized void addBlobStore(BlobStoreInfo info) { } // ensure there isn't a BlobStoreInfo with the same name already if (getBlobStoreNames().contains(info.getName())) { - throw new IllegalArgumentException(String.format( - "Failed to add BlobStoreInfo. A BlobStoreInfo with name \"%s\" already exists", info.getName())); + throw new IllegalArgumentException("Failed to add BlobStoreInfo. A BlobStoreInfo with name \"%s\" already exists".formatted(info.getName())); } // add the BlobStoreInfo final List blobStores = getGwcConfig().getBlobStores(); @@ -970,7 +968,7 @@ public synchronized void addBlobStore(BlobStoreInfo info) { } catch (IOException ioe) { // save failed, roll back the add blobStores.remove(info); - throw new ConfigurationPersistenceException(String.format("Unable to add BlobStoreInfo \"%s\"", info), ioe); + throw new ConfigurationPersistenceException("Unable to add BlobStoreInfo \"%s\"".formatted(info), ioe); } try { blobStoreListeners.safeForEach(listener -> { @@ -981,7 +979,7 @@ public synchronized void addBlobStore(BlobStoreInfo info) { // Can't store here, roll back blobStores.remove(info); throw new ConfigurationPersistenceException( - String.format("Unable to add BlobStoreInfo \"%s\"", info), e); + "Unable to add BlobStoreInfo \"%s\"".formatted(info), e); } throw new ConfigurationPersistenceException(e); } @@ -992,8 +990,7 @@ public synchronized void addBlobStore(BlobStoreInfo info) { public synchronized void removeBlobStore(String name) { // ensure there is a BlobStoreInfo with the name final BlobStoreInfo infoToRemove = getBlobStore(name) - .orElseThrow(() -> new NoSuchElementException(String.format( - "Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.", name))); + .orElseThrow(() -> new NoSuchElementException("Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted(name))); // remove the BlobStoreInfo final List blobStores = getGwcConfig().getBlobStores(); blobStores.remove(infoToRemove); @@ -1004,7 +1001,7 @@ public synchronized void removeBlobStore(String name) { // save failed, roll back the delete blobStores.add(infoToRemove); throw new ConfigurationPersistenceException( - String.format("Unable to remove BlobStoreInfo \"%s\"", name), ioe); + "Unable to remove BlobStoreInfo \"%s\"".formatted(name), ioe); } try { blobStoreListeners.safeForEach(listener -> { @@ -1023,9 +1020,8 @@ public synchronized void modifyBlobStore(BlobStoreInfo info) { } // ensure there is a BlobStoreInfo with the name final Optional optionalInfo = getBlobStore(info.getName()); - if (!optionalInfo.isPresent()) { - throw new NoSuchElementException(String.format( - "Failed to modify BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.", + if (optionalInfo.isEmpty()) { + throw new NoSuchElementException("Failed to modify BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted( info.getName())); } // remove existing and add the new one @@ -1041,7 +1037,7 @@ public synchronized void modifyBlobStore(BlobStoreInfo info) { blobStores.remove(info); blobStores.add(infoToRemove); throw new ConfigurationPersistenceException( - String.format("Unable to modify BlobStoreInfo \"%s\"", info.getName()), ioe); + "Unable to modify BlobStoreInfo \"%s\"".formatted(info.getName()), ioe); } try { blobStoreListeners.safeForEach(listener -> { @@ -1053,7 +1049,7 @@ public synchronized void modifyBlobStore(BlobStoreInfo info) { blobStores.remove(info); blobStores.add(infoToRemove); throw new ConfigurationPersistenceException( - String.format("Unable to modify BlobStoreInfo \"%s\"", info), e); + "Unable to modify BlobStoreInfo \"%s\"".formatted(info), e); } throw new ConfigurationPersistenceException(e); } @@ -1137,7 +1133,7 @@ public void renameBlobStore(String oldName, String newName) save(); if (log.isLoggable(Level.FINER)) { - log.finer(String.format("BlobStoreInfo rename from \"%s\" to \"%s\" successful.", oldName, newName)); + log.finer("BlobStoreInfo rename from \"%s\" to \"%s\" successful.".formatted(oldName, newName)); } } catch (IOException ioe) { // save didn't work, need to roll things back @@ -1154,15 +1150,14 @@ public void renameBlobStore(String oldName, String newName) if (blobStoreInfoToRevert == null) { // we're really messed up now as we couldn't find the BlobStoreInfo that was just // renamed. - throw new ConfigurationPersistenceException(String.format( - "Error reverting BlobStoreInfo modification. Could not revert rename from \"%s\" to \"%s\"", + throw new ConfigurationPersistenceException("Error reverting BlobStoreInfo modification. Could not revert rename from \"%s\" to \"%s\"".formatted( oldName, newName)); } // revert the name and add it back to the list blobStoreInfoToRevert.setName(oldName); blobStoreInfos.add(blobStoreInfoToRevert); throw new ConfigurationPersistenceException( - String.format("Unable to rename BlobStoreInfo from \"%s\" to \"%s\"", oldName, newName), ioe); + "Unable to rename BlobStoreInfo from \"%s\" to \"%s\"".formatted(oldName, newName), ioe); } try { blobStoreListeners.safeForEach(listener -> { @@ -1170,8 +1165,7 @@ public void renameBlobStore(String oldName, String newName) }); } catch (IOException | GeoWebCacheException e) { throw new ConfigurationPersistenceException( - String.format( - "Exception while handling listeners for renaming blobstore \"%s\" to \"%s\"", + "Exception while handling listeners for renaming blobstore \"%s\" to \"%s\"".formatted( oldName, newName), e); } diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSet.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSet.java index c1707cab0..9cd85c6de 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSet.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSet.java @@ -13,6 +13,7 @@ */ package org.geowebcache.config; +import java.io.Serial; import java.io.Serializable; import java.util.Arrays; import org.geowebcache.grid.BoundingBox; @@ -27,6 +28,7 @@ */ public class XMLGridSet implements Serializable { + @Serial private static final long serialVersionUID = 2684804068163933728L; private String name; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSubset.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSubset.java index e61289523..aaf811c73 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSubset.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLGridSubset.java @@ -13,6 +13,7 @@ */ package org.geowebcache.config; +import java.io.Serial; import java.io.Serializable; import java.util.logging.Level; import java.util.logging.Logger; @@ -30,6 +31,7 @@ */ public class XMLGridSubset implements Serializable, Cloneable { + @Serial private static final long serialVersionUID = 2758612849329765806L; private static Logger log = Logging.getLogger(XMLGridSubset.class.getName()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java index 7b72e939f..a3898d370 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java @@ -13,6 +13,7 @@ */ package org.geowebcache.config; +import java.io.Serial; import java.io.Serializable; import org.geowebcache.grid.BoundingBox; import org.geowebcache.grid.GridSet; @@ -32,6 +33,7 @@ }) // field assignment done by XStream public class XMLOldGrid implements Serializable { + @Serial private static final long serialVersionUID = 1413422643636728997L; private SRS srs = null; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceContact.java b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceContact.java index 9b781eac5..6c37da633 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceContact.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceContact.java @@ -13,10 +13,12 @@ */ package org.geowebcache.config.meta; +import java.io.Serial; import java.io.Serializable; public class ServiceContact implements Serializable { + @Serial private static final long serialVersionUID = 2137310743590604314L; private String individualName; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceInformation.java b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceInformation.java index 9cd7a2c98..49fb80264 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceInformation.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceInformation.java @@ -13,12 +13,14 @@ */ package org.geowebcache.config.meta; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.List; public class ServiceInformation implements Serializable { + @Serial private static final long serialVersionUID = -4466383328619274445L; private String title; diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceProvider.java b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceProvider.java index 5019304f2..79c8d5479 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceProvider.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/meta/ServiceProvider.java @@ -13,10 +13,12 @@ */ package org.geowebcache.config.meta; +import java.io.Serial; import java.io.Serializable; public class ServiceProvider implements Serializable { + @Serial private static final long serialVersionUID = 6318645093724139893L; private String providerName; diff --git a/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java b/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java index 18c840579..fc8b1303c 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java +++ b/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java @@ -129,38 +129,44 @@ private static String generateHTML(TileLayerDispatcher tileLayerDispatcher, Grid buf.append(ServletUtils.gwcHtmlHeader("", "GWC Demos")); buf.append("\n"); buf.append(ServletUtils.gwcHtmlLogoLink("")); - buf.append("
\n" - + "\n" - + "\n" - + "\n"); + buf.append(""" +
Layer name:Enabled:Grids Sets:
+ + + + """); buf.append("\n"); tableRows(buf, tileLayerDispatcher, gridSetBroker); buf.append("
Layer name:Enabled:Grids Sets:
\n"); buf.append("
"); - buf.append("These are just quick demos. GeoWebCache also supports:
\n" - + "
  • WMTS, TMS, Virtual Earth and Google Maps
  • \n" - + "
  • Proxying GetFeatureInfo, GetLegend and other WMS requests
  • \n" - + "
  • Advanced request and parameter filters
  • \n" - + "
  • Output format adjustments, such as compression level
  • \n" - + "
  • Adjustable expiration headers and automatic cache expiration
  • \n" - + "
  • RESTful interface for seeding and configuration (beta)
  • \n" - + "
\n" - + "
\n" - + "Reload TileLayerConfiguration:
\n" - + "

You can reload the configuration by pressing the following button. " - + "The username / password is configured in WEB-INF/user.properties, or the admin " - + " user in GeoServer if you are using the plugin.

\n" - + "
These are just quick demos. GeoWebCache also supports:
+
  • WMTS, TMS, Virtual Earth and Google Maps
  • +
  • Proxying GetFeatureInfo, GetLegend and other WMS requests
  • +
  • Advanced request and parameter filters
  • +
  • Output format adjustments, such as compression level
  • +
  • Adjustable expiration headers and automatic cache expiration
  • +
  • RESTful interface for seeding and configuration (beta)
  • +
+
+ Reload TileLayerConfiguration:
+

You can reload the configuration by pressing the following button. \ + The username / password is configured in WEB-INF/user.properties, or the admin \ + user in GeoServer if you are using the plugin.

+ " - + "" - + "" - + "
" - + "
Truncate All Layers:
\n" - + "

Truncate all layers" - + "

\ + \ + \ +
\ +
Truncate All Layers:
+

Truncate all layers\ +

\" value=\"\"/>" + "" @@ -224,11 +230,9 @@ private static void outputKMLSupport(StringBuffer buf, TileLayer layer) { .filter(type -> type instanceof ImageMime || XMLMime.kml.equals(type) || XMLMime.kmz.equals(type)) .map(type -> { if (XMLMime.kmz.equals(type)) { - return String.format( - "kmz", prefix, escapeHtml4(layer.getName())); + return "kmz".formatted(prefix, escapeHtml4(layer.getName())); } else { - return String.format( - "%s", + return "%s".formatted( prefix, escapeHtml4(layer.getName()), type.getFileExtension(), type.getFileExtension()); } }) @@ -238,8 +242,7 @@ private static void outputKMLSupport(StringBuffer buf, TileLayer layer) { } private static String generateDemoUrl(String layerName, String gridSetId, MimeType type) { - return String.format( - "%s", + return "%s".formatted( layerName, gridSetId, type.getFormat(), type.getFileExtension()); } @@ -274,18 +277,20 @@ private static String generateHTML(TileLayer layer, String gridSetStr, String fo buf.append(" ").append(escapeHtml4(gridSubset.getName())); buf.append(" ").append(escapeHtml4(formatStr)); buf.append("\n"); - buf.append("\n"); + buf.append(""" + + """); buf.append("\n"); buf.append("\n"); @@ -296,13 +301,14 @@ private static String generateHTML(TileLayer layer, String gridSetStr, String fo .append("\n"); buf.append("
\n" + "
\n"); - buf.append("
\n" - + "
\n" - + " Attributes\n" - + " \n" - + "
\n" - + "
\n" - + "
"); + buf.append(""" +
+
+ Attributes + +
+
+
"""); // add parameters in hidden inputs makeHiddenInput(buf, "dpi", Double.toString(gridSubset.getDotsPerInch())); @@ -311,7 +317,7 @@ private static String generateHTML(TileLayer layer, String gridSetStr, String fo buf, "gridNames", Arrays.stream(gridSubset.getGridNames()) - .map(s -> String.format("\"%s\"", s)) + .map(s -> "\"%s\"".formatted(s)) .collect(Collectors.joining(", ", "[", "]"))); makeHiddenInput( buf, @@ -403,8 +409,7 @@ private static String makeModifiableParameters(TileLayer tl) { makePullDown(doc, parameterId, keysValues, defaultValue); } else if (pf instanceof RegexParameterFilter) { makeTextInput(doc, parameterId, 25); - } else if (pf instanceof FloatParameterFilter) { - FloatParameterFilter floatParam = (FloatParameterFilter) pf; + } else if (pf instanceof FloatParameterFilter floatParam) { if (floatParam.getValues().isEmpty()) { // accepts any value makeTextInput(doc, parameterId, 25); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizer.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizer.java index fc9777a50..936374d27 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizer.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizer.java @@ -15,6 +15,7 @@ import com.google.common.base.Function; import com.thoughtworks.xstream.annotations.XStreamAlias; +import java.io.Serial; import java.io.Serializable; import java.util.Locale; import java.util.Objects; @@ -26,6 +27,7 @@ * @author Kevin Smith, Boundless */ public class CaseNormalizer implements Function, Serializable, Cloneable { + @Serial private static final long serialVersionUID = -4175693577236472098L; /** diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizingParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizingParameterFilter.java index c7b089991..6c5455927 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizingParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/CaseNormalizingParameterFilter.java @@ -14,11 +14,13 @@ package org.geowebcache.filter.parameters; import com.google.common.collect.Lists; +import java.io.Serial; import java.util.List; import java.util.Objects; import javax.annotation.Nullable; public abstract class CaseNormalizingParameterFilter extends ParameterFilter { + @Serial private static final long serialVersionUID = 1761619452677321350L; protected CaseNormalizer normalize; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/FloatParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/FloatParameterFilter.java index 9eacb671c..c75e6d7df 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/FloatParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/FloatParameterFilter.java @@ -15,6 +15,7 @@ import com.google.common.base.Preconditions; import com.thoughtworks.xstream.annotations.XStreamAlias; +import java.io.Serial; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; @@ -27,6 +28,7 @@ @XStreamAlias("floatParameterFilter") public class FloatParameterFilter extends ParameterFilter { + @Serial private static final long serialVersionUID = 4186888723396139208L; private static Float DEFAULT_THRESHOLD = Float.valueOf(1E-6f); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/IntegerParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/IntegerParameterFilter.java index 442cb0a1d..04a835c9f 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/IntegerParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/IntegerParameterFilter.java @@ -16,6 +16,7 @@ import com.google.common.base.Preconditions; import com.thoughtworks.xstream.annotations.XStreamAlias; +import java.io.Serial; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; @@ -27,6 +28,7 @@ @ParametersAreNonnullByDefault @XStreamAlias("integerParameterFilter") public class IntegerParameterFilter extends ParameterFilter { + @Serial private static final long serialVersionUID = 659566920877534621L; private static Integer DEFAULT_THRESHOLD = Integer.valueOf(1); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterException.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterException.java index e00bd271b..910ca85ea 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterException.java @@ -13,11 +13,13 @@ */ package org.geowebcache.filter.parameters; +import java.io.Serial; import org.geowebcache.GeoWebCacheException; /** A problem occurred while filtering a parameter. */ public class ParameterException extends GeoWebCacheException { + @Serial private static final long serialVersionUID = 2471474123508934754L; private final int httpCode; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterFilter.java index 331ce3daf..6132aea84 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/ParameterFilter.java @@ -14,6 +14,7 @@ package org.geowebcache.filter.parameters; import com.google.common.base.Preconditions; +import java.io.Serial; import java.io.Serializable; import java.util.List; import java.util.Objects; @@ -25,6 +26,7 @@ @ParametersAreNonnullByDefault public abstract class ParameterFilter implements Serializable, Cloneable { + @Serial private static final long serialVersionUID = -531248230951783132L; private String key; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/RegexParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/RegexParameterFilter.java index 7180b4555..857daaa8e 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/RegexParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/RegexParameterFilter.java @@ -15,6 +15,7 @@ import com.google.common.base.Preconditions; import com.thoughtworks.xstream.annotations.XStreamAlias; +import java.io.Serial; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -26,6 +27,7 @@ @XStreamAlias("regexParameterFilter") public class RegexParameterFilter extends CaseNormalizingParameterFilter { + @Serial private static final long serialVersionUID = -1496940509350980799L; public static final String DEFAULT_EXPRESSION = ""; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/StringParameterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/StringParameterFilter.java index ea09a0f75..663c959f4 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/StringParameterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/parameters/StringParameterFilter.java @@ -15,6 +15,7 @@ import com.google.common.base.Preconditions; import com.thoughtworks.xstream.annotations.XStreamAlias; +import java.io.Serial; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -25,6 +26,7 @@ @XStreamAlias("stringParameterFilter") public class StringParameterFilter extends CaseNormalizingParameterFilter { + @Serial private static final long serialVersionUID = 7383381085250203901L; private List values; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/BlankTileException.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/BlankTileException.java index b5ff46788..6b6549a10 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/BlankTileException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/BlankTileException.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.util.logging.Level; import java.util.logging.Logger; import org.geotools.util.logging.Logging; @@ -29,6 +30,7 @@ */ public class BlankTileException extends RequestFilterException { /** */ + @Serial private static final long serialVersionUID = 6910805463474341350L; private static Logger log = Logging.getLogger(BlankTileException.class.getName()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/CircularExtentFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/CircularExtentFilter.java index 40a20fa5b..6468282ab 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/CircularExtentFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/CircularExtentFilter.java @@ -13,6 +13,7 @@ */ package org.geowebcache.filter.request; +import java.io.Serial; import org.geowebcache.GeoWebCacheException; import org.geowebcache.conveyor.ConveyorTile; import org.geowebcache.grid.GridSubset; @@ -27,6 +28,7 @@ */ public class CircularExtentFilter extends RequestFilter { + @Serial private static final long serialVersionUID = -8488899568092162423L; CircularExtentFilter() {} diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/FileRasterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/FileRasterFilter.java index e3872af5c..66013efce 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/FileRasterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/FileRasterFilter.java @@ -17,12 +17,14 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.Serial; import javax.imageio.ImageIO; import org.geowebcache.GeoWebCacheException; import org.geowebcache.layer.TileLayer; public class FileRasterFilter extends RasterFilter { + @Serial private static final long serialVersionUID = -6950985531575208956L; private String storagePath; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/GreenTileException.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/GreenTileException.java index 5ff450055..ea320f2fd 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/GreenTileException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/GreenTileException.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.util.logging.Level; import java.util.logging.Logger; import org.geotools.util.logging.Logging; @@ -28,6 +29,7 @@ */ public class GreenTileException extends RequestFilterException { /** */ + @Serial private static final long serialVersionUID = -3369293469656922254L; private static Logger log = Logging.getLogger(GreenTileException.class.getName()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RasterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RasterFilter.java index 908623f4f..691f0135a 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RasterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RasterFilter.java @@ -15,6 +15,7 @@ import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.Serial; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; @@ -37,6 +38,7 @@ */ public abstract class RasterFilter extends RequestFilter { + @Serial private static final long serialVersionUID = -5695649347572928323L; private static Logger log = Logging.getLogger(RasterFilter.class.getName()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilter.java index 0ac6a94dd..5d41e56c6 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilter.java @@ -13,6 +13,7 @@ */ package org.geowebcache.filter.request; +import java.io.Serial; import java.io.Serializable; import org.geowebcache.GeoWebCacheException; import org.geowebcache.conveyor.ConveyorTile; @@ -21,6 +22,7 @@ /** This is just a dummy class. Should be abstract, but that gets tricky with XStream */ public abstract class RequestFilter implements Serializable { + @Serial private static final long serialVersionUID = -1058186522442111377L; private String name; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilterException.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilterException.java index b5c942cf4..fb5ec2131 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilterException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/RequestFilterException.java @@ -13,10 +13,12 @@ */ package org.geowebcache.filter.request; +import java.io.Serial; import javax.servlet.http.HttpServletResponse; import org.geowebcache.io.Resource; public class RequestFilterException extends Exception { + @Serial private static final long serialVersionUID = -6790605482047043946L; RequestFilter reqFilter; diff --git a/geowebcache/core/src/main/java/org/geowebcache/filter/request/WMSRasterFilter.java b/geowebcache/core/src/main/java/org/geowebcache/filter/request/WMSRasterFilter.java index 007155600..76d6fc1db 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/filter/request/WMSRasterFilter.java +++ b/geowebcache/core/src/main/java/org/geowebcache/filter/request/WMSRasterFilter.java @@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.Serial; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -37,6 +38,7 @@ public class WMSRasterFilter extends RasterFilter { + @Serial private static final long serialVersionUID = 5565794752696452109L; private static Logger log = Logging.getLogger(RasterFilter.class.getName()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBox.java b/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBox.java index f958f8547..1b956028a 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBox.java +++ b/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBox.java @@ -13,6 +13,7 @@ */ package org.geowebcache.grid; +import java.io.Serial; import java.io.Serializable; import java.text.NumberFormat; import java.util.Arrays; @@ -23,6 +24,7 @@ public class BoundingBox implements Serializable { + @Serial private static final long serialVersionUID = -2555598825074884627L; private NumberFormat getCoordinateFormatter() { @@ -222,8 +224,7 @@ public String toKMLLatLonAltBox() { */ @Override public boolean equals(Object obj) { - if (obj instanceof BoundingBox) { - BoundingBox other = (BoundingBox) obj; + if (obj instanceof BoundingBox other) { return this.equals(other, EQUALITYTHRESHOLD); } return false; diff --git a/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBoxException.java b/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBoxException.java index 9eb69f607..565becd30 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBoxException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/grid/BoundingBoxException.java @@ -13,9 +13,11 @@ */ package org.geowebcache.grid; +import java.io.Serial; import org.geowebcache.GeoWebCacheException; public class BoundingBoxException extends GeoWebCacheException { + @Serial private static final long serialVersionUID = -3727985329718467002L; public BoundingBoxException(String msg) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/grid/Grid.java b/geowebcache/core/src/main/java/org/geowebcache/grid/Grid.java index 327dd3c01..d405a9088 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/grid/Grid.java +++ b/geowebcache/core/src/main/java/org/geowebcache/grid/Grid.java @@ -13,12 +13,14 @@ */ package org.geowebcache.grid; +import java.io.Serial; import java.io.Serializable; import java.util.Objects; /** @author groldan */ public class Grid implements Serializable, Cloneable { + @Serial private static final long serialVersionUID = 1L; private long numTilesWide; diff --git a/geowebcache/core/src/main/java/org/geowebcache/grid/OutsideCoverageException.java b/geowebcache/core/src/main/java/org/geowebcache/grid/OutsideCoverageException.java index 6da6a8883..8e649a2e5 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/grid/OutsideCoverageException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/grid/OutsideCoverageException.java @@ -13,11 +13,13 @@ */ package org.geowebcache.grid; +import java.io.Serial; import java.util.Arrays; import org.geowebcache.GeoWebCacheException; public class OutsideCoverageException extends GeoWebCacheException { /** */ + @Serial private static final long serialVersionUID = -2465389680194367974L; public OutsideCoverageException(long[] index, long firstLevel, long lastLevel) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/io/ByteArrayResource.java b/geowebcache/core/src/main/java/org/geowebcache/io/ByteArrayResource.java index 48c7c2a35..e18afc2ab 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/io/ByteArrayResource.java +++ b/geowebcache/core/src/main/java/org/geowebcache/io/ByteArrayResource.java @@ -105,8 +105,7 @@ public long transferTo(WritableByteChannel channel) throws IOException { @Override @SuppressWarnings("PMD.EmptyControlStatement") public long transferFrom(ReadableByteChannel channel) throws IOException { - if (channel instanceof FileChannel) { - FileChannel fc = (FileChannel) channel; + if (channel instanceof FileChannel fc) { offset = 0; length = (int) fc.size(); if (data == null || data.length < length) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/io/GeoWebCacheXStream.java b/geowebcache/core/src/main/java/org/geowebcache/io/GeoWebCacheXStream.java index 8a8bd7e43..528b6290e 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/io/GeoWebCacheXStream.java +++ b/geowebcache/core/src/main/java/org/geowebcache/io/GeoWebCacheXStream.java @@ -384,10 +384,10 @@ private void registerConverterDynamically( Class.forName(className, false, getClassLoaderReference().getReference()); Constructor constructor = type.getConstructor(constructorParamTypes); Object instance = constructor.newInstance(constructorParamValues); - if (instance instanceof Converter) { - registerConverter((Converter) instance, priority); - } else if (instance instanceof SingleValueConverter) { - registerConverter((SingleValueConverter) instance, priority); + if (instance instanceof Converter converter1) { + registerConverter(converter1, priority); + } else if (instance instanceof SingleValueConverter converter) { + registerConverter(converter, priority); } } catch (Exception | LinkageError e) { throw new com.thoughtworks.xstream.InitializationException( diff --git a/geowebcache/core/src/main/java/org/geowebcache/layer/BadTileException.java b/geowebcache/core/src/main/java/org/geowebcache/layer/BadTileException.java index 57131b817..d4597500d 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/layer/BadTileException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/layer/BadTileException.java @@ -13,10 +13,12 @@ */ package org.geowebcache.layer; +import java.io.Serial; import org.geowebcache.GeoWebCacheException; public class BadTileException extends GeoWebCacheException { /** */ + @Serial private static final long serialVersionUID = -8591262755936233177L; public BadTileException(String msg) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/layer/MetaTile.java b/geowebcache/core/src/main/java/org/geowebcache/layer/MetaTile.java index af2ce0732..7f3e9a7e0 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/layer/MetaTile.java +++ b/geowebcache/core/src/main/java/org/geowebcache/layer/MetaTile.java @@ -306,8 +306,8 @@ private Rectangle[] createTiles(int tileHeight, int tileWidth) { public RenderedImage createTile(final int minX, final int minY, final int tileWidth, final int tileHeight) { // optimize if we get a bufferedimage - if (metaTileImage instanceof BufferedImage) { - BufferedImage subimage = ((BufferedImage) metaTileImage).getSubimage(minX, minY, tileWidth, tileHeight); + if (metaTileImage instanceof BufferedImage image) { + BufferedImage subimage = image.getSubimage(minX, minY, tileWidth, tileHeight); return new BufferedImageAdapter(subimage); } @@ -473,20 +473,20 @@ public void dispose() { if (log.isLoggable(Level.FINER)) { log.finer("disposing metatile " + image); } - if (image instanceof BufferedImage) { - ((BufferedImage) image).flush(); - } else if (image instanceof PlanarImage) { - disposePlanarImageChain((PlanarImage) image, new HashSet<>()); + if (image instanceof BufferedImage bufferedImage) { + bufferedImage.flush(); + } else if (image instanceof PlanarImage planarImage) { + disposePlanarImageChain(planarImage, new HashSet<>()); } if (disposableImages != null) { for (RenderedImage tile : disposableImages) { if (log.isLoggable(Level.FINER)) { log.finer("disposing tile " + tile); } - if (tile instanceof BufferedImage) { - ((BufferedImage) tile).flush(); - } else if (tile instanceof PlanarImage) { - disposePlanarImageChain((PlanarImage) tile, new HashSet<>()); + if (tile instanceof BufferedImage bufferedImage) { + bufferedImage.flush(); + } else if (tile instanceof PlanarImage planarImage) { + disposePlanarImageChain(planarImage, new HashSet<>()); } } } @@ -498,10 +498,10 @@ protected static void disposePlanarImageChain(PlanarImage pi, HashSet> getParameters(String layerName) throws StorageException { return getParametersMapping(layerName).values().stream() - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .collect(Collectors.toSet()); } diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java b/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java index 3b09e7cf9..7b34c1cfd 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java @@ -96,8 +96,7 @@ public BlobStoreInfo getBlobStore(final String blobStoreName) throws GeoWebCache return getConfigs().stream() .map(c -> c.getBlobStore(blobStoreName)) - .filter(Optional::isPresent) - .map(Optional::get) + .flatMap(Optional::stream) .findFirst() .orElseThrow(() -> new GeoWebCacheException("Thread " + Thread.currentThread().getName() @@ -197,9 +196,9 @@ private int initialize(BlobStoreConfiguration config) { } // Check whether there is any general service information - if (this.serviceInformation == null && config instanceof ServerConfiguration) { + if (this.serviceInformation == null && config instanceof ServerConfiguration configuration) { log.fine("Reading service information."); - this.serviceInformation = ((ServerConfiguration) config).getServiceInformation(); + this.serviceInformation = configuration.getServiceInformation(); } return blobStoreCount; } diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/MetastoreRemover.java b/geowebcache/core/src/main/java/org/geowebcache/storage/MetastoreRemover.java index 598adf6ef..5b2dc48af 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/MetastoreRemover.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/MetastoreRemover.java @@ -104,11 +104,12 @@ private void removeTiles(JdbcTemplate template) { private void migrateParameters(JdbcTemplate template, final File root) { // find all possible combinations of layer, zoom level, gridset and parameter id String query = - "select layers.value as layer, gridsets.value as gridset, tiles.z, parameters.value as parameters, parameters_id\n" - + "from tiles join layers on layers.id = tiles.layer_id \n" - + " join gridsets on gridsets.id = tiles.gridset_id\n" - + " join parameters on parameters.id = tiles.parameters_id\n" - + "group by layer, gridset, z, parameters, parameters_id"; + """ + select layers.value as layer, gridsets.value as gridset, tiles.z, parameters.value as parameters, parameters_id + from tiles join layers on layers.id = tiles.layer_id\s + join gridsets on gridsets.id = tiles.gridset_id + join parameters on parameters.id = tiles.parameters_id + group by layer, gridset, z, parameters, parameters_id"""; final long total = Optional.ofNullable( template.queryForObject("select count(*) from (" + query + ")", Long.class)) @@ -180,12 +181,13 @@ private Map toMap(String paramsKvp) { } private void migrateTileDates(JdbcTemplate template, final FilePathGenerator generator) { - String query = "select layers.value as layer, gridsets.value as gridset, " - + "tiles.parameters_id, tiles.z, tiles.x, tiles.y, created, formats.value as format \n" - + "from tiles join layers on layers.id = tiles.layer_id \n" - + "join gridsets on gridsets.id = tiles.gridset_id \n" - + "join formats on formats.id = tiles.format_id \n" - + "order by layer_id, parameters_id, gridset, z, x, y"; + String query = """ + select layers.value as layer, gridsets.value as gridset, \ + tiles.parameters_id, tiles.z, tiles.x, tiles.y, created, formats.value as format\s + from tiles join layers on layers.id = tiles.layer_id\s + join gridsets on gridsets.id = tiles.gridset_id\s + join formats on formats.id = tiles.format_id\s + order by layer_id, parameters_id, gridset, z, x, y"""; final long total = Optional.ofNullable( template.queryForObject("select count(*) from (" + query + ")", Long.class)) diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/StorageException.java b/geowebcache/core/src/main/java/org/geowebcache/storage/StorageException.java index bc4216e7d..d456f47c6 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/StorageException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/StorageException.java @@ -14,8 +14,10 @@ package org.geowebcache.storage; import java.io.IOException; +import java.io.Serial; public class StorageException extends IOException { + @Serial private static final long serialVersionUID = -8168546310999238936L; String msg; diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/TileObject.java b/geowebcache/core/src/main/java/org/geowebcache/storage/TileObject.java index 61765fb9c..b7f5c0475 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/TileObject.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/TileObject.java @@ -13,6 +13,7 @@ */ package org.geowebcache.storage; +import java.io.Serial; import java.io.Serializable; import java.util.Arrays; import java.util.Map; @@ -25,6 +26,7 @@ */ public class TileObject extends StorageObject implements Serializable { /** serialVersionUID */ + @Serial private static final long serialVersionUID = 2204318806003485110L; public static final String TYPE = "tile"; diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/TileRangeIterator.java b/geowebcache/core/src/main/java/org/geowebcache/storage/TileRangeIterator.java index 79777582f..a06ee1a5b 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/TileRangeIterator.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/TileRangeIterator.java @@ -37,8 +37,8 @@ public TileRangeIterator(TileRange tr, int[] metaTilingFactors) { this.metaX = metaTilingFactors[0]; this.metaY = metaTilingFactors[1]; - if (tr instanceof DiscontinuousTileRange) { - dtr = (DiscontinuousTileRange) tr; + if (tr instanceof DiscontinuousTileRange range) { + dtr = range; } else { dtr = null; } diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/UnsuitableStorageException.java b/geowebcache/core/src/main/java/org/geowebcache/storage/UnsuitableStorageException.java index 594931cb9..08a49f925 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/UnsuitableStorageException.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/UnsuitableStorageException.java @@ -13,6 +13,8 @@ */ package org.geowebcache.storage; +import java.io.Serial; + /** * Thrown when a Blobstore was initialized with persistance that is unsuitable, such as a non-empty directory * @@ -21,6 +23,7 @@ public class UnsuitableStorageException extends StorageException { /** serialVersionUID */ + @Serial private static final long serialVersionUID = 3939772540460067187L; public UnsuitableStorageException(String msg) { diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FileBlobStore.java b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FileBlobStore.java index 1c43922dd..3eb201cd7 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FileBlobStore.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FileBlobStore.java @@ -720,7 +720,7 @@ public boolean deleteByParametersId(String layerName, String parametersId) throw } catch (IOException e) { log.log( Level.WARNING, - String.format("Failed to clean up metadata for parameters %s in layer %s", parametersId, layerName), + "Failed to clean up metadata for parameters %s in layer %s".formatted(parametersId, layerName), e); } diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FilePathUtils.java b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FilePathUtils.java index 16abb030d..d14520a98 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FilePathUtils.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/file/FilePathUtils.java @@ -88,7 +88,7 @@ public static int findZoomLevel(final String gridsetPrefix, final String dirName try { return Integer.parseInt(zlevel); } catch (NumberFormatException e) { - throw new RuntimeException(String.format("unable to find zoom level in '%s'", gridsetPrefix), e); + throw new RuntimeException("unable to find zoom level in '%s'".formatted(gridsetPrefix), e); } } diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheConfiguration.java b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheConfiguration.java index 42887c46d..8b3bf664c 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheConfiguration.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheConfiguration.java @@ -13,6 +13,7 @@ */ package org.geowebcache.storage.blobstore.memory; +import java.io.Serial; import java.io.Serializable; import java.util.Objects; @@ -24,6 +25,7 @@ public class CacheConfiguration implements Serializable { /** serialVersionUID */ + @Serial private static final long serialVersionUID = 3875121032331372267L; /** Evction policy */ diff --git a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheStatistics.java b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheStatistics.java index c0a47e225..efc6b2f98 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheStatistics.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/blobstore/memory/CacheStatistics.java @@ -13,6 +13,7 @@ */ package org.geowebcache.storage.blobstore.memory; +import java.io.Serial; import java.io.Serializable; /** @@ -24,6 +25,7 @@ public class CacheStatistics implements Serializable { /** serialVersionUID */ + @Serial private static final long serialVersionUID = -1049287017217353112L; /** Cache hit count */ diff --git a/geowebcache/core/src/main/java/org/geowebcache/util/FileUtils.java b/geowebcache/core/src/main/java/org/geowebcache/util/FileUtils.java index 11b58d875..db762327e 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/util/FileUtils.java +++ b/geowebcache/core/src/main/java/org/geowebcache/util/FileUtils.java @@ -18,7 +18,6 @@ import java.io.FilenameFilter; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.List; @@ -125,8 +124,8 @@ public static boolean renameFile(File src, File dst) { } // 1) try with Java 7 Files.move - Path srcPath = Paths.get(src.toURI()); - Path dstPath = Paths.get(dst.toURI()); + Path srcPath = Path.of(src.toURI()); + Path dstPath = Path.of(dst.toURI()); Path moved = null; try { // Execute renaming diff --git a/geowebcache/core/src/main/java/org/geowebcache/util/GWCVars.java b/geowebcache/core/src/main/java/org/geowebcache/util/GWCVars.java index 561e7ce2b..f05d8e81f 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/util/GWCVars.java +++ b/geowebcache/core/src/main/java/org/geowebcache/util/GWCVars.java @@ -51,8 +51,8 @@ public static enum VariableType { }, SERVLET("servlet context parameter") { protected @Override String apply(ApplicationContext context, String varName) { - if (context instanceof WebApplicationContext) { - ServletContext servletContext = ((WebApplicationContext) context).getServletContext(); + if (context instanceof WebApplicationContext applicationContext) { + ServletContext servletContext = applicationContext.getServletContext(); return servletContext == null ? null : servletContext.getInitParameter(varName); } return null; diff --git a/geowebcache/core/src/main/java/org/geowebcache/util/ServletUtils.java b/geowebcache/core/src/main/java/org/geowebcache/util/ServletUtils.java index 365102dca..37e8181d1 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/util/ServletUtils.java +++ b/geowebcache/core/src/main/java/org/geowebcache/util/ServletUtils.java @@ -110,7 +110,7 @@ public static Map selectedStringsFromMap(Map map, Str for (String key : keys) { Object value = map.get(key); if (value != null) { - String sValue = value instanceof String[] ? ((String[]) value)[0] : String.valueOf(value); + String sValue = value instanceof String[] ss ? ss[0] : String.valueOf(value); selected.put(key.toUpperCase(), URLDecode(sValue, encoding)); } } diff --git a/geowebcache/core/src/main/java/org/geowebcache/util/TMSKeyBuilder.java b/geowebcache/core/src/main/java/org/geowebcache/util/TMSKeyBuilder.java index 47ca0fcac..edb120ca9 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/util/TMSKeyBuilder.java +++ b/geowebcache/core/src/main/java/org/geowebcache/util/TMSKeyBuilder.java @@ -214,7 +214,7 @@ public String coordinatesPrefix(TileRange obj, boolean endWithSlash) { } public String pendingDeletes() { - if (!Strings.isNullOrEmpty(prefix)) return String.format("%s/%s", prefix, PENDING_DELETES); + if (!Strings.isNullOrEmpty(prefix)) return "%s/%s".formatted(prefix, PENDING_DELETES); else return PENDING_DELETES; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/TestHelpers.java b/geowebcache/core/src/test/java/org/geowebcache/TestHelpers.java index 16edba023..97f5d436a 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/TestHelpers.java +++ b/geowebcache/core/src/test/java/org/geowebcache/TestHelpers.java @@ -111,8 +111,8 @@ public static Matcher hasStatus(HttpStatus expected) { @Override public boolean matches(Object item) { - if (item instanceof HttpServletResponse) { - return expected.equals(HttpStatus.valueOf(((HttpServletResponse) item).getStatus())); + if (item instanceof HttpServletResponse response) { + return expected.equals(HttpStatus.valueOf(response.getStatus())); } return false; } @@ -129,8 +129,8 @@ protected void describeStatus(HttpStatus status, Description description) { @Override public void describeMismatch(Object item, Description description) { - if (item instanceof HttpServletResponse) { - HttpStatus status = HttpStatus.valueOf(((HttpServletResponse) item).getStatus()); + if (item instanceof HttpServletResponse response) { + HttpStatus status = HttpStatus.valueOf(response.getStatus()); description.appendText("status was "); describeStatus(status, description); } else { diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java index bbca75e0a..3aed89f4f 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultGridsetsConfigurationGridsetConformanceTest.java @@ -42,9 +42,9 @@ protected Matcher infoEquals(GridSet expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && ((GridSet) item).getName().equals(expected.getName()) - && ((GridSet) item).getDescription().equals(expected.getDescription()); + return item instanceof GridSet gs + && gs.getName().equals(expected.getName()) + && gs.getDescription().equals(expected.getDescription()); } }; } @@ -55,8 +55,8 @@ protected Matcher infoEquals(int expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && ((GridSet) item).getDescription().equals(Integer.toString(expected)); + return item instanceof GridSet gs + && gs.getDescription().equals(Integer.toString(expected)); } }; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java index e5ab400d2..c514a785b 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java @@ -103,8 +103,7 @@ public void setDefaultValues(TileLayer layer) { } } - if (layer instanceof WMSLayer) { - WMSLayer wl = (WMSLayer) layer; + if (layer instanceof WMSLayer wl) { URL proxyUrl = null; try { diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationBlobStoreConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationBlobStoreConformanceTest.java index 874d0a7a9..d4e51e3a0 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationBlobStoreConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationBlobStoreConformanceTest.java @@ -142,8 +142,8 @@ protected Matcher infoEquals(int expected) { @Override public boolean matches(Object item) { - return item instanceof FileBlobStoreInfo - && (Objects.equals(((FileBlobStoreInfo) item).getFileSystemBlockSize(), expected)); + return item instanceof FileBlobStoreInfo fbsi + && (Objects.equals(fbsi.getFileSystemBlockSize(), expected)); } }; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationGridsetConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationGridsetConformanceTest.java index 53596a2d7..ecfa10730 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationGridsetConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationGridsetConformanceTest.java @@ -70,9 +70,9 @@ protected Matcher infoEquals(GridSet expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && ((GridSet) item).getName().equals(expected.getName()) - && ((GridSet) item).getDescription().equals(expected.getDescription()); + return item instanceof GridSet gs + && gs.getName().equals(expected.getName()) + && gs.getDescription().equals(expected.getDescription()); } }; } @@ -83,8 +83,8 @@ protected Matcher infoEquals(int expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && (Objects.equals(((GridSet) item).getDescription(), Integer.toString(expected))); + return item instanceof GridSet gs + && (Objects.equals(gs.getDescription(), Integer.toString(expected))); } }; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java index 772dca929..4c4bfeae9 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/XMLConfigurationLayerConformanceTest.java @@ -147,9 +147,9 @@ protected Matcher infoEquals(TileLayer expected) { @Override public boolean matches(Object item) { - return item instanceof WMSLayer - && ((WMSLayer) item).getId().equals(expected.getId()) - && ((WMSLayer) item).getWmsLayers().equals(((WMSLayer) expected).getWmsLayers()); + return item instanceof WMSLayer wmsl + && wmsl.getId().equals(expected.getId()) + && wmsl.getWmsLayers().equals(((WMSLayer) expected).getWmsLayers()); } }; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java index ce45a7b47..07b4b03db 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/FloatParameterFilterTest.java @@ -109,31 +109,33 @@ public void testThreshold() throws Exception { @Test public void testToXML() throws Exception { XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " 42.0\n" - + " 6.283\n" - + " -17.5\n" - + " \n" - + " 1.0E-5\n" - + "", + """ + + TEST + Default + + 42.0 + 6.283 + -17.5 + + 1.0E-5 + """, xs.toXML(filter)); } @Test public void testFromXML() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " 42\n" - + " 6.283\n" - + " -17.5\n" - + " \n" - + " 0.00001\n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + 42 + 6.283 + -17.5 + + 0.00001 + """); assertThat(o, instanceOf(FloatParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java index e8c87a02d..6c0c402a7 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/IntegerParameterFilterTest.java @@ -115,35 +115,37 @@ public void testThreshold() throws Exception { @Test public void testToXML() throws Exception { XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " 42\n" - + " 2\n" - + " 0\n" - + " -1\n" - + " -200\n" - + " \n" - + " 1\n" - + "", + """ + + TEST + Default + + 42 + 2 + 0 + -1 + -200 + + 1 + """, xs.toXML(filter)); } @Test public void testFromXML() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " 42\n" - + " 2\n" - + " 0\n" - + " -1\n" - + " -200\n" - + " \n" - + " 15\n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + 42 + 2 + 0 + -1 + -200 + + 15 + """); assertThat(o, instanceOf(IntegerParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java index b8a19a537..177849113 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/ParametersUtilsTest.java @@ -132,8 +132,8 @@ static Matcher> hasEntries(Matcher>... entryMatcher @Override public boolean matches(Object item) { - if (item instanceof Map) { - return entrySetMatcher.matches(((Map) item).entrySet()); + if (item instanceof Map map) { + return entrySetMatcher.matches(map.entrySet()); } else { return false; } diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java index b8233e20a..285376fd2 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/RegexParameterFilterTest.java @@ -171,11 +171,12 @@ public void testNormalizeLocale() throws Exception { @Test public void testToXMLNullNormalizer() throws Exception { XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " foo|Bar|BAZ\n" - + "", + """ + + TEST + Default + foo|Bar|BAZ + """, xs.toXML(filter)); } @@ -183,12 +184,13 @@ public void testToXMLNullNormalizer() throws Exception { public void testToXMLDefaultNormalizer() throws Exception { filter.setNormalize(new CaseNormalizer()); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " foo|Bar|BAZ\n" - + "", + """ + + TEST + Default + + foo|Bar|BAZ + """, xs.toXML(filter)); } @@ -196,14 +198,15 @@ public void testToXMLDefaultNormalizer() throws Exception { public void testToXMLNoneNormalizer() throws Exception { filter.setNormalize(new CaseNormalizer(Case.NONE)); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " NONE\n" - + " \n" - + " foo|Bar|BAZ\n" - + "", + """ + + TEST + Default + + NONE + + foo|Bar|BAZ + """, xs.toXML(filter)); } @@ -211,29 +214,31 @@ public void testToXMLNoneNormalizer() throws Exception { public void testToXMLUpperCanadianEnglish() throws Exception { filter.setNormalize(new CaseNormalizer(Case.UPPER, Locale.CANADA)); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " UPPER\n" - + " en_CA\n" - + " \n" - + " foo|Bar|BAZ\n" - + "", + """ + + TEST + Default + + UPPER + en_CA + + foo|Bar|BAZ + """, xs.toXML(filter)); } @Test public void testFromXMLUpperCanadianEnglish() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " UPPER\n" - + " en_CA\n" - + " \n" - + " foo|Bar|BAZ\n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + UPPER + en_CA + + foo|Bar|BAZ + """); assertThat(o, instanceOf(RegexParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); @@ -251,15 +256,16 @@ public void testFromXMLUpperCanadianEnglish() throws Exception { @Test public void testFromXMLIdentifiersCaseInsensitive() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " uPPer\n" - + " EN_ca\n" - + " \n" - + " foo|Bar|BAZ\n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + uPPer + EN_ca + + foo|Bar|BAZ + """); assertThat(o, instanceOf(RegexParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); @@ -278,11 +284,12 @@ public void testFromXMLIdentifiersCaseInsensitive() throws Exception { @Test public void testFromXMLDefaultNormalize() throws Exception { // important for backward compatibility with older config files - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " foo|Bar|BAZ\n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + foo|Bar|BAZ + """); assertThat(o, instanceOf(RegexParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); diff --git a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java index 06488bf15..b2df3d0fc 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/filter/parameters/StringParameterFilterTest.java @@ -169,15 +169,16 @@ public void testNormalizeLocale() throws Exception { @Test public void testToXMLNullNormalizer() throws Exception { XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + "", + """ + + TEST + Default + + foo + Bar + BAZ + + """, xs.toXML(filter)); } @@ -185,16 +186,17 @@ public void testToXMLNullNormalizer() throws Exception { public void testToXMLDefaultNormalizer() throws Exception { filter.setNormalize(new CaseNormalizer()); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + "", + """ + + TEST + Default + + + foo + Bar + BAZ + + """, xs.toXML(filter)); } @@ -202,18 +204,19 @@ public void testToXMLDefaultNormalizer() throws Exception { public void testToXMLNoneNormalizer() throws Exception { filter.setNormalize(new CaseNormalizer(Case.NONE)); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " NONE\n" - + " \n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + "", + """ + + TEST + Default + + NONE + + + foo + Bar + BAZ + + """, xs.toXML(filter)); } @@ -221,37 +224,39 @@ public void testToXMLNoneNormalizer() throws Exception { public void testToXMLUpperCanadianEnglish() throws Exception { filter.setNormalize(new CaseNormalizer(Case.UPPER, Locale.CANADA)); XMLAssert.assertXMLEqual( - "\n" - + " TEST\n" - + " Default\n" - + " \n" - + " UPPER\n" - + " en_CA\n" - + " \n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + "", + """ + + TEST + Default + + UPPER + en_CA + + + foo + Bar + BAZ + + """, xs.toXML(filter)); } @Test public void testFromXMLUpperCanadianEnglish() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " UPPER\n" - + " en_CA\n" - + " \n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + UPPER + en_CA + + + foo + Bar + BAZ + + """); assertThat(o, instanceOf(StringParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); @@ -269,19 +274,20 @@ public void testFromXMLUpperCanadianEnglish() throws Exception { @Test public void testFromXMLIdentifiersCaseInsensitive() throws Exception { - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " uPPer\n" - + " EN_ca\n" - + " \n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + uPPer + EN_ca + + + foo + Bar + BAZ + + """); assertThat(o, instanceOf(StringParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); @@ -300,15 +306,16 @@ public void testFromXMLIdentifiersCaseInsensitive() throws Exception { @Test public void testFromXMLDefaultNormalize() throws Exception { // important for backward compatibility with older config files - Object o = xs.fromXML("\n" - + " TEST\n" - + " Default\n" - + " \n" - + " foo\n" - + " Bar\n" - + " BAZ\n" - + " \n" - + ""); + Object o = xs.fromXML(""" + + TEST + Default + + foo + Bar + BAZ + + """); assertThat(o, instanceOf(StringParameterFilter.class)); assertThat(o, hasProperty("key", equalTo("TEST"))); diff --git a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/MetaTileTest.java b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/MetaTileTest.java index 5f8877b0b..7beb7710b 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/MetaTileTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/MetaTileTest.java @@ -298,8 +298,8 @@ private void commonCreateTileFromMetaTileTest(Color[][] colors, RenderedImage me // Helper method that given an image and a color will check that the borders of the image are of // the same color private void checkImageBorderSameColor(RenderedImage image, Color color) throws Exception { - if (image instanceof PlanarImage) { - image = ((PlanarImage) image).getAsBufferedImage(); + if (image instanceof PlanarImage planarImage) { + image = planarImage.getAsBufferedImage(); } // extracting the borders pixels int width = image.getWidth(); diff --git a/geowebcache/core/src/test/java/org/geowebcache/util/FileMatchers.java b/geowebcache/core/src/test/java/org/geowebcache/util/FileMatchers.java index 894dd0e82..2f91e9632 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/util/FileMatchers.java +++ b/geowebcache/core/src/test/java/org/geowebcache/util/FileMatchers.java @@ -43,8 +43,8 @@ public static Matcher exists() { @Override public boolean matches(Object item) { - if (item instanceof File) { - return ((File) item).exists(); + if (item instanceof File file) { + return file.exists(); } else { return false; } @@ -74,8 +74,8 @@ public static Matcher file() { @Override public boolean matches(Object item) { - if (item instanceof File) { - return ((File) item).isFile(); + if (item instanceof File file) { + return file.isFile(); } else { return false; } @@ -88,8 +88,8 @@ public void describeTo(Description description) { @Override public void describeMismatch(Object item, Description description) { - if (item instanceof File) { - if (((File) item).exists()) { + if (item instanceof File file) { + if (file.exists()) { description.appendValue(item); description.appendText(" is a directory"); } else { @@ -110,8 +110,8 @@ public static Matcher directory() { @Override public boolean matches(Object item) { - if (item instanceof File) { - return ((File) item).isDirectory(); + if (item instanceof File file) { + return file.isDirectory(); } else { return false; } @@ -124,8 +124,8 @@ public void describeTo(Description description) { @Override public void describeMismatch(Object item, Description description) { - if (item instanceof File) { - if (((File) item).exists()) { + if (item instanceof File file) { + if (file.exists()) { description.appendValue(item); description.appendText(" is not a directory"); } else { @@ -146,9 +146,9 @@ public static Matcher directoryContaining(Matcher> filesMat @Override public boolean matches(Object item) { - if (item instanceof File) { - return ((File) item).isDirectory() - && filesMatcher.matches(Arrays.asList(((File) item).listFiles())); + if (item instanceof File file) { + return file.isDirectory() + && filesMatcher.matches(Arrays.asList(file.listFiles())); } else { return false; } @@ -190,8 +190,8 @@ public static Matcher lastModified(final Matcher timeMatcher) { @Override public boolean matches(Object item) { - if (item instanceof File) { - return timeMatcher.matches(((File) item).lastModified()); + if (item instanceof File file) { + return timeMatcher.matches(file.lastModified()); } else { return false; } @@ -205,11 +205,11 @@ public void describeTo(Description description) { @Override public void describeMismatch(Object item, Description description) { - if (item instanceof File) { - if (((File) item).exists()) { + if (item instanceof File file) { + if (file.exists()) { description.appendValue(item); description.appendText(" had modification time "); - timeMatcher.describeMismatch(((File) item).lastModified(), description); + timeMatcher.describeMismatch(file.lastModified(), description); } else { description.appendValue(item); description.appendText(" does not exist"); @@ -244,8 +244,8 @@ public static Matcher resource(final Resource expected) { @Override public boolean matches(Object item) { - if (item instanceof Resource) { - try (InputStream itemStream = ((Resource) item).getInputStream(); + if (item instanceof Resource resource) { + try (InputStream itemStream = resource.getInputStream(); InputStream expectedStream = expected.getInputStream()) { return IOUtils.contentEquals(itemStream, expectedStream); } catch (IOException e) { diff --git a/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSLayerSource.java b/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSLayerSource.java index a3f864fe6..b5f48c28d 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSLayerSource.java +++ b/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSLayerSource.java @@ -31,13 +31,15 @@ public class MockWMSLayerSource { private static final Logger log = Logging.getLogger(MockWMSLayerSource.class.getName()); public MockWMSLayerSource(TileLayerDispatcher tld) { - log.info("'\n---------------------------------------------------------------------------------\n" - + "Replacing all WMS layer backend helpers by a mock one, don't forget to remove this\n" - + "---------------------------------------------------------------------------------"); + log.info(""" + ' + --------------------------------------------------------------------------------- + Replacing all WMS layer backend helpers by a mock one, don't forget to remove this + ---------------------------------------------------------------------------------"""); for (TileLayer layer : tld.getLayerList()) { - if (layer instanceof WMSLayer) { - ((WMSLayer) layer).setSourceHelper(fakeWMSSource); + if (layer instanceof WMSLayer sLayer) { + sLayer.setSourceHelper(fakeWMSSource); } } } diff --git a/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSSourceHelper.java b/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSSourceHelper.java index b4a09a4fb..a1f29bb81 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSSourceHelper.java +++ b/geowebcache/core/src/test/java/org/geowebcache/util/MockWMSSourceHelper.java @@ -38,8 +38,7 @@ protected void makeRequest( int tileW; int tileH; String format; - if (tileRespRecv instanceof ConveyorTile) { - ConveyorTile conveyorTile = (ConveyorTile) tileRespRecv; + if (tileRespRecv instanceof ConveyorTile conveyorTile) { long[] tileIndex = conveyorTile.getTileIndex(); tiles = new long[1][1]; tiles[0] = tileIndex; diff --git a/geowebcache/core/src/test/java/org/geowebcache/util/TestUtils.java b/geowebcache/core/src/test/java/org/geowebcache/util/TestUtils.java index 94fb3f0f1..581bf34e5 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/util/TestUtils.java +++ b/geowebcache/core/src/test/java/org/geowebcache/util/TestUtils.java @@ -171,7 +171,7 @@ public void describeTo(Description description) { public void describeMismatch(Object item, Description description) { if (!(item instanceof Optional)) { description.appendText(item.toString() + " is not an Optional"); - } else if (!((Optional) item).isPresent()) { + } else if (((Optional) item).isEmpty()) { description.appendText("Value was not present"); } else { valueMatcher.describeMismatch(((Optional) item).get(), description); diff --git a/geowebcache/diskquota/bdb/src/main/java/org/geowebcache/diskquota/bdb/BDBQuotaStore.java b/geowebcache/diskquota/bdb/src/main/java/org/geowebcache/diskquota/bdb/BDBQuotaStore.java index 4cf6c5372..8daeb96e1 100644 --- a/geowebcache/diskquota/bdb/src/main/java/org/geowebcache/diskquota/bdb/BDBQuotaStore.java +++ b/geowebcache/diskquota/bdb/src/main/java/org/geowebcache/diskquota/bdb/BDBQuotaStore.java @@ -327,8 +327,8 @@ private E issueSync(final Callable command) throws InterruptedException { } catch (ExecutionException e) { log.log(Level.WARNING, e.getMessage(), e); Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) { - throw (RuntimeException) cause; + if (cause instanceof RuntimeException exception) { + throw exception; } throw new RuntimeException(cause); } diff --git a/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java b/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java index 9e5a5aea4..a248d38b1 100644 --- a/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java +++ b/geowebcache/diskquota/bdb/src/test/java/org/geowebcache/diskquota/BDBQuotaStoreTest.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.Future; +import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.Stream; import org.easymock.Capture; @@ -517,7 +518,7 @@ public void testGetUsedQuotaByTileSetId() throws Exception { Map expectedById = new HashMap<>(); for (TileSet tset : tileSets) { - Quota quotaDiff = new Quota(10D * Math.random(), StorageUnit.MiB); + Quota quotaDiff = new Quota(10D * ThreadLocalRandom.current().nextDouble(), StorageUnit.MiB); store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET); store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET); Quota tsetQuota = new Quota(quotaDiff); @@ -563,8 +564,8 @@ static Matcher closeTo(float f, float epsilon) { @Override @SuppressWarnings("SelfAssignment") // this actually changes its fp representation public boolean matches(Object item) { - if (item instanceof Float) { - item = (double) (float) item; + if (item instanceof Float float1) { + item = (double) float1; } return doubleMatcher.matches(item); } diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/DiskQuotaConfig.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/DiskQuotaConfig.java index c56e06ad6..e1822904d 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/DiskQuotaConfig.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/DiskQuotaConfig.java @@ -13,6 +13,7 @@ */ package org.geowebcache.diskquota; +import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; @@ -34,6 +35,7 @@ */ public class DiskQuotaConfig implements Cloneable, Serializable { + @Serial private static final long serialVersionUID = 4376471696761297546L; @Deprecated diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/LayerQuota.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/LayerQuota.java index fcf84bb26..f970b9d04 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/LayerQuota.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/LayerQuota.java @@ -13,12 +13,14 @@ */ package org.geowebcache.diskquota.storage; +import java.io.Serial; import java.io.Serializable; import org.geowebcache.diskquota.ExpirationPolicy; /** @author groldan */ public final class LayerQuota implements Serializable { + @Serial private static final long serialVersionUID = 5726170502452942487L; private String layer; diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PageStats.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PageStats.java index 09289a72e..613cee64f 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PageStats.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PageStats.java @@ -13,6 +13,7 @@ */ package org.geowebcache.diskquota.storage; +import java.io.Serial; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; @@ -27,6 +28,7 @@ @SuppressWarnings("PMD.AvoidDecimalLiteralsInBigDecimalConstructor") public class PageStats implements Serializable { + @Serial private static final long serialVersionUID = 719776699585233200L; @SuppressWarnings("PMD.UnusedPrivateField") diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/Quota.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/Quota.java index adf792dec..c2d214ce3 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/Quota.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/Quota.java @@ -13,6 +13,7 @@ */ package org.geowebcache.diskquota.storage; +import java.io.Serial; import java.io.Serializable; import java.math.BigDecimal; import java.math.BigInteger; @@ -28,6 +29,7 @@ */ public class Quota implements Cloneable, Comparable, Serializable { + @Serial private static final long serialVersionUID = -3817255124248938529L; private static final NumberFormat NICE_FORMATTER = NumberFormat.getNumberInstance(); diff --git a/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCConfiguration.java b/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCConfiguration.java index 9c92110dd..ef8f2749d 100644 --- a/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCConfiguration.java +++ b/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCConfiguration.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.Serial; import java.io.Serializable; import java.util.logging.Logger; import org.apache.commons.lang3.SerializationUtils; @@ -230,6 +231,7 @@ public String toString() { * @author Andrea Aime - GeoSolutions */ public static class ConnectionPoolConfiguration implements Serializable { + @Serial private static final long serialVersionUID = 6677252877141737936L; String driver; diff --git a/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStore.java b/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStore.java index 5b99fdc44..d5ad4334e 100644 --- a/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStore.java +++ b/geowebcache/diskquota/jdbc/src/main/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStore.java @@ -684,10 +684,10 @@ public void close() throws Exception { log.info("Closing up the JDBC quota store "); // try to close the data source if possible - if (dataSource instanceof BasicDataSource) { - ((BasicDataSource) dataSource).close(); - } else if (dataSource instanceof Closeable) { - ((Closeable) dataSource).close(); + if (dataSource instanceof BasicDataSource source) { + source.close(); + } else if (dataSource instanceof Closeable closeable) { + closeable.close(); } // release the templates diff --git a/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java b/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java index 05c355943..fa3befd81 100644 --- a/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java +++ b/geowebcache/diskquota/jdbc/src/test/java/org/geowebcache/diskquota/jdbc/JDBCQuotaStoreTest.java @@ -27,6 +27,7 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.Future; +import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.sql.DataSource; @@ -569,7 +570,7 @@ public void testGetUsedQuotaByTileSetId() throws Exception { Map expectedById = new HashMap<>(); for (TileSet tset : tileSets) { - Quota quotaDiff = new Quota(10D * Math.random(), StorageUnit.MiB); + Quota quotaDiff = new Quota(10D * ThreadLocalRandom.current().nextDouble(), StorageUnit.MiB); store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET); store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.EMPTY_SET); Quota tsetQuota = new Quota(quotaDiff); @@ -590,7 +591,7 @@ public void testUpdateUsedQuotaWithParameters() throws Exception { String paramId = DigestUtils.sha1Hex("&styles=polygon"); TileSet tset = new TileSet("topp:states2", "EPSG:2163", "image/jpeg", paramId); - Quota quotaDiff = new Quota(10D * Math.random(), StorageUnit.MiB); + Quota quotaDiff = new Quota(10D * ThreadLocalRandom.current().nextDouble(), StorageUnit.MiB); PageStatsPayload stats = new PageStatsPayload(new TilePage(tset.getId(), 0, 0, 3)); stats.setNumTiles(10); store.addToQuotaAndTileCounts(tset, quotaDiff, Collections.singletonList(stats)); diff --git a/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java b/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java index 348f7279f..0735017fa 100644 --- a/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java +++ b/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java @@ -217,8 +217,12 @@ private void _logImagesToDisk(final GeometryRasterMaskBuilder matrix) { "Can't access debug directory for " + "dumping mask images: " + target.getAbsolutePath()); } - LOGGER.warning("\n!!!!!!!!!!!\n REMEMBER NOT TO SET THE org.geowebcache.georss.debugToDisk" - + " SYSTEM PROPERTY ON A PRODUCTION ENVIRONMENT \n!!!!!!!!!!!"); + LOGGER.warning(""" + + !!!!!!!!!!! + REMEMBER NOT TO SET THE org.geowebcache.georss.debugToDisk\ + SYSTEM PROPERTY ON A PRODUCTION ENVIRONMENT\s + !!!!!!!!!!!"""); BufferedImage[] byLevelMasks = matrix.getByLevelMasks(); for (int i = 0; i < byLevelMasks.length; i++) { diff --git a/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPoller.java b/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPoller.java index b1ed42e75..c904e15e9 100644 --- a/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPoller.java +++ b/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPoller.java @@ -108,8 +108,7 @@ private void findEnabledPolls() { + "' as the layer is disabled"); } for (UpdateSourceDefinition usd : layer.getUpdateSources()) { - if (usd instanceof GeoRSSFeedDefinition) { - final GeoRSSFeedDefinition georssDef = (GeoRSSFeedDefinition) usd; + if (usd instanceof GeoRSSFeedDefinition georssDef) { final String gridSetId = georssDef.getGridSetId(); final GridSubset gridSubset = layer.getGridSubset(gridSetId); diff --git a/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLService.java b/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLService.java index 53e1d17c8..0825b6ee5 100644 --- a/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLService.java +++ b/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLService.java @@ -688,11 +688,13 @@ private static String getLookAt(BoundingBox bbox) { } private static String KMLHeader() { - return "\n" - + "\n"; + return """ + + + """; } // private static String moreDataIcon(BBOX bbox){ diff --git a/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLSiteMap.java b/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLSiteMap.java index a2de55592..323e85360 100644 --- a/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLSiteMap.java +++ b/geowebcache/kml/src/main/java/org/geowebcache/service/kml/KMLSiteMap.java @@ -63,8 +63,10 @@ private void writeSiteMapIndex() throws IOException { @SuppressWarnings("PMD.CloseResource") // managed by servlet container OutputStream os = tile.servletResp.getOutputStream(); - String header = "\n" - + "\n"; + String header = """ + + + """; os.write(header.getBytes()); writeSiteMapIndexLoop(); @@ -129,8 +131,10 @@ private void writeSiteMap() throws GeoWebCacheException, IOException { } private void writeSiteMapHeader() throws IOException { - String header = "\n" - + "\n"; + String header = """ + + + """; tile.servletResp.getOutputStream().write(header.getBytes()); } diff --git a/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java b/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java index 993414d07..46073ab1e 100644 --- a/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java +++ b/geowebcache/mbtiles/src/test/java/org/geowebcache/mbtiles/layer/MBTilesLayerTest.java @@ -27,7 +27,7 @@ import java.io.InputStream; import java.net.URL; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.HashSet; @@ -93,14 +93,14 @@ private void makeConfigFile() throws Exception { File lakesFile = temp.newFile("world_lakes.mbtiles"); URL source = MBTilesLayerTest.class.getResource("world_lakes.mbtiles"); - Files.copy(Paths.get(source.toURI()), lakesFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(Path.of(source.toURI()), lakesFile.toPath(), StandardCopyOption.REPLACE_EXISTING); File pointsFile = temp.newFile(TEST_POINTS_FILENAME); source = MBTilesLayerTest.class.getResource(TEST_POINTS_FILENAME); - Files.copy(Paths.get(source.toURI()), pointsFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.copy(Path.of(source.toURI()), pointsFile.toPath(), StandardCopyOption.REPLACE_EXISTING); source = MBTilesLayerTest.class.getResource("geowebcache.xml"); - try (Stream lines = Files.lines(Paths.get(source.toURI()))) { + try (Stream lines = Files.lines(Path.of(source.toURI()))) { List replaced = lines.map(line -> { return line.replace("world_lakes.mbtiles", lakesFile.getAbsolutePath()) .replace(TEST_POINTS_FILENAME, pointsFile.getAbsolutePath()) diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/BlobStoreController.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/BlobStoreController.java index d7be85347..ea3217b5e 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/BlobStoreController.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/BlobStoreController.java @@ -54,8 +54,7 @@ public BlobStoreInfo blobStoreGet(@PathVariable String blobStoreName) { return blobStores.getBlobStore(blobStoreName); } catch (GeoWebCacheException e) { throw new RestException( - String.format( - "Failed to get BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.", + "Failed to get BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted( blobStoreName), HttpStatus.NOT_FOUND, e); @@ -83,8 +82,7 @@ public void blobStoreDelete(@PathVariable String blobStoreName) { blobStores.removeBlobStore(blobStoreName); } else { throw new RestException( - String.format( - "Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.", + "Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted( blobStoreName), HttpStatus.NOT_FOUND); } diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/GridSetController.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/GridSetController.java index aec1d77ec..77befa30c 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/GridSetController.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/GridSetController.java @@ -53,7 +53,7 @@ public GridSet gridSetGet(@PathVariable String gridSetName) { return broker.get(gridSetName); } else { throw new RestException( - String.format("Failed to get GridSet. A GridSet with name \"%s\" does not exist.", gridSetName), + "Failed to get GridSet. A GridSet with name \"%s\" does not exist.".formatted(gridSetName), HttpStatus.NOT_FOUND); } } @@ -79,7 +79,7 @@ public void gridSetDelete(@PathVariable String gridSetName) { broker.removeGridSet(gridSetName); } else { throw new RestException( - String.format("Failed to remove GridSet. A GridSet with name \"%s\" does not exist.", gridSetName), + "Failed to remove GridSet. A GridSet with name \"%s\" does not exist.".formatted(gridSetName), HttpStatus.NOT_FOUND); } } diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/MemoryCacheController.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/MemoryCacheController.java index 067cb491a..dbe9ed313 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/MemoryCacheController.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/controller/MemoryCacheController.java @@ -84,16 +84,14 @@ public ResponseEntity doGet(HttpServletRequest request) { } // Getting the BlobStore if present - if (broker instanceof DefaultStorageBroker) { - store = ((DefaultStorageBroker) broker).getBlobStore(); + if (broker instanceof DefaultStorageBroker storageBroker) { + store = storageBroker.getBlobStore(); } - if (store != null && store instanceof MemoryBlobStore) { + if (store != null && store instanceof MemoryBlobStore memoryStore) { if (log.isLoggable(Level.FINE)) { log.fine("Memory Blobstore found, now getting statistics"); } - // Getting statistics - MemoryBlobStore memoryStore = (MemoryBlobStore) store; CacheStatistics stats = memoryStore.getCacheStatistics(); CacheStatistics statistics = new CacheStatistics(stats); diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/converter/GWCConverter.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/converter/GWCConverter.java index dd27fc609..1ba08adcb 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/converter/GWCConverter.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/converter/GWCConverter.java @@ -116,17 +116,17 @@ protected T readInternal(Class clazz, HttpInputMessage httpInputMes } else { throw new RestException("Unknown or missing format", HttpStatus.UNSUPPORTED_MEDIA_TYPE); } - if (object instanceof XMLGridSet) { - return (T) ((XMLGridSet) object).makeGridSet(); + if (object instanceof XMLGridSet set) { + return (T) set.makeGridSet(); } return object; } catch (ConversionException xstreamExceptionWrapper) { Throwable cause = xstreamExceptionWrapper.getCause(); - if (cause instanceof Error) { - throw (Error) cause; + if (cause instanceof Error error) { + throw error; } - if (cause instanceof RuntimeException) { - throw (RuntimeException) cause; + if (cause instanceof RuntimeException exception) { + throw exception; } if (cause != null) { throw new RestException(cause.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR, cause); @@ -150,13 +150,13 @@ protected void writeInternal(T object, HttpOutputMessage httpOutputMessage) XStream xs = new GeoWebCacheXStream(); Object xsObject = object; - if (object instanceof XStreamListAliasWrapper) { - final XStreamListAliasWrapper wrapper = ((XStreamListAliasWrapper) object); + if (object instanceof XStreamListAliasWrapper aliasWrapper) { + final XStreamListAliasWrapper wrapper = aliasWrapper; xsObject = wrapper.object; xs.alias(wrapper.alias + "s", wrapper.collectionClass); xs.registerConverter(wrapper.createConverter()); - } else if (object instanceof GridSet) { - xsObject = new XMLGridSet((GridSet) object); + } else if (object instanceof GridSet set) { + xsObject = new XMLGridSet(set); } xs = configureXStream(XMLConfiguration.getConfiguredXStreamWithContext( @@ -170,10 +170,10 @@ protected void writeInternal(T object, HttpOutputMessage httpOutputMessage) context, ContextualConfigurationProvider.Context.REST)); Object jsonObject; - if (object instanceof XStreamListAliasWrapper) { - jsonObject = new JSONArray(((XStreamListAliasWrapper) object).object); - } else if (object instanceof GridSet) { - jsonObject = new JSONObject(xs.toXML(new XMLGridSet((GridSet) object))); + if (object instanceof XStreamListAliasWrapper wrapper) { + jsonObject = new JSONArray(wrapper.object); + } else if (object instanceof GridSet set) { + jsonObject = new JSONObject(xs.toXML(new XMLGridSet(set))); } else { jsonObject = new JSONObject(xs.toXML(object)); } diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/exception/RestException.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/exception/RestException.java index 208ed7d0e..c29170757 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/exception/RestException.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/exception/RestException.java @@ -15,6 +15,7 @@ */ package org.geowebcache.rest.exception; +import java.io.Serial; import org.springframework.http.HttpStatus; /** @@ -24,6 +25,7 @@ @SuppressWarnings("OverrideThrowableToString") public class RestException extends RuntimeException { /** serialVersionUID */ + @Serial private static final long serialVersionUID = 5762645820684796082L; private final HttpStatus status; diff --git a/geowebcache/rest/src/main/java/org/geowebcache/rest/service/FormService.java b/geowebcache/rest/src/main/java/org/geowebcache/rest/service/FormService.java index fb1a044f6..8a59abc88 100644 --- a/geowebcache/rest/src/main/java/org/geowebcache/rest/service/FormService.java +++ b/geowebcache/rest/src/main/java/org/geowebcache/rest/service/FormService.java @@ -350,8 +350,7 @@ private void makeModifiableParameters(StringBuilder doc, TileLayer tl) { makePullDown(doc, parameterId, keysValues, defaultValue); } else if (pf instanceof RegexParameterFilter) { makeTextInput(doc, parameterId, 25); - } else if (pf instanceof FloatParameterFilter) { - FloatParameterFilter floatFilter = (FloatParameterFilter) pf; + } else if (pf instanceof FloatParameterFilter floatFilter) { if (floatFilter.getValues().isEmpty()) { // accepts any value makeTextInput(doc, parameterId, 25); @@ -619,12 +618,14 @@ private void makeHeader(StringBuilder doc) { } private void makeWarningsAndHints(StringBuilder doc, TileLayer tl) { - doc.append("

Please note:

    \n" - + "
  • This minimalistic interface does not check for correctness.
  • \n" - + "
  • Seeding past zoomlevel 20 is usually not recommended.
  • \n" - + "
  • Truncating KML will also truncate all KMZ archives.
  • \n" - + "
  • Please check the logs of the container to look for error messages and progress indicators.
  • \n" - + "
\n"); + doc.append(""" +

Please note:

    +
  • This minimalistic interface does not check for correctness.
  • +
  • Seeding past zoomlevel 20 is usually not recommended.
  • +
  • Truncating KML will also truncate all KMZ archives.
  • +
  • Please check the logs of the container to look for error messages and progress indicators.
  • +
+ """); doc.append("Here are the max bounds, if you do not specify bounds these will be used.\n"); doc.append("
    \n"); diff --git a/geowebcache/rest/src/test/java/org/geowebcache/rest/filter/FilterUpdateControllerTest.java b/geowebcache/rest/src/test/java/org/geowebcache/rest/filter/FilterUpdateControllerTest.java index 1adc96142..700580850 100644 --- a/geowebcache/rest/src/test/java/org/geowebcache/rest/filter/FilterUpdateControllerTest.java +++ b/geowebcache/rest/src/test/java/org/geowebcache/rest/filter/FilterUpdateControllerTest.java @@ -86,11 +86,12 @@ private XMLConfiguration loadXMLConfig() { @Test public void testPost() throws Exception { - String filterXml = "\n" - + " EPSG:4326\n" - + " 0\n" - + " 6\n" - + ""; + String filterXml = """ + + EPSG:4326 + 0 + 6 + """; this.mockMvc .perform(post("/rest/filter/testWMSRasterFilter/update/xml") diff --git a/geowebcache/rest/src/test/java/org/geowebcache/rest/service/FormServiceTest.java b/geowebcache/rest/src/test/java/org/geowebcache/rest/service/FormServiceTest.java index 084004c73..0629bf3a6 100644 --- a/geowebcache/rest/src/test/java/org/geowebcache/rest/service/FormServiceTest.java +++ b/geowebcache/rest/src/test/java/org/geowebcache/rest/service/FormServiceTest.java @@ -162,21 +162,22 @@ public void testThreads() { // in lexicographic order after 10 there was 100 String html = service.makeFormPage(tl1, false); - assertTrue(html.contains(" + + + + + + + + + + + + + + + """)); } } diff --git a/geowebcache/s3storage/pom.xml b/geowebcache/s3storage/pom.xml index 65d884907..c70f55aa8 100644 --- a/geowebcache/s3storage/pom.xml +++ b/geowebcache/s3storage/pom.xml @@ -20,6 +20,12 @@ gwc-core ${project.version} + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + com.amazonaws aws-java-sdk-s3 diff --git a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStore.java b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStore.java index fb8912611..982a18dbe 100644 --- a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStore.java +++ b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStore.java @@ -15,7 +15,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import static java.lang.String.format; import static java.util.Objects.isNull; import com.amazonaws.AmazonServiceException; @@ -240,8 +239,8 @@ public void put(TileObject obj) throws StorageException { private ByteArrayInputStream toByteArray(final Resource blob) throws StorageException { final byte[] bytes; - if (blob instanceof ByteArrayResource) { - bytes = ((ByteArrayResource) blob).getContents(); + if (blob instanceof ByteArrayResource resource) { + bytes = resource.getContents(); } else { try (ByteArrayOutputStream out = new ByteArrayOutputStream((int) blob.getSize()); WritableByteChannel channel = Channels.newChannel(out)) { @@ -300,7 +299,7 @@ public boolean delete(final TileRange tileRange) throws StorageException { private String scheduleDeleteForZoomLevel(TileRange tileRange, int level) { String zoomPath = keyBuilder.forZoomLevel(tileRange, level); Bounds bounds = new Bounds(tileRange.rangeBounds(level)); - String prefix = format("%s?%s", zoomPath, bounds); + String prefix = "%s?%s".formatted(zoomPath, bounds); try { s3Ops.scheduleAsyncDelete(prefix); return prefix; @@ -519,7 +518,7 @@ static String prefixWithoutBounds(String prefix) { @Override public String toString() { - return format("bounds=%d,%d,%d,%d", minX, minY, maxX, maxY); + return "bounds=%d,%d,%d,%d".formatted(minX, minY, maxX, maxY); } public boolean predicate(S3ObjectSummary s3ObjectSummary) { diff --git a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStoreInfo.java b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStoreInfo.java index 8a150ad92..7aa3b3daa 100644 --- a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStoreInfo.java +++ b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3BlobStoreInfo.java @@ -26,6 +26,7 @@ import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.S3ClientOptions; import com.amazonaws.services.s3.model.CannedAccessControlList; +import java.io.Serial; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.Nullable; @@ -45,6 +46,7 @@ public class S3BlobStoreInfo extends BlobStoreInfo { static Logger log = Logging.getLogger(S3BlobStoreInfo.class.getName()); + @Serial private static final long serialVersionUID = 9072751143836460389L; private String bucket; @@ -392,9 +394,9 @@ public String getLocation() { String bucket = this.getBucket(); String prefix = this.getPrefix(); if (prefix == null) { - return String.format("bucket: %s", bucket); + return "bucket: %s".formatted(bucket); } else { - return String.format("bucket: %s prefix: %s", bucket, prefix); + return "bucket: %s prefix: %s".formatted(bucket, prefix); } } diff --git a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3Ops.java b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3Ops.java index 49198d100..58a630cbb 100644 --- a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3Ops.java +++ b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/S3Ops.java @@ -125,7 +125,7 @@ private void issuePendingBulkDeletes() throws StorageException { final String prefix = e.getKey().toString(); final long timestamp = Long.parseLong(e.getValue().toString()); S3BlobStore.log.info( - String.format("Restarting pending bulk delete on '%s/%s':%d", bucketName, prefix, timestamp)); + "Restarting pending bulk delete on '%s/%s':%d".formatted(bucketName, prefix, timestamp)); pendingDeletesKeyTime.put(prefix, timestamp); boolean nothingToDelete = !asyncDelete(prefix, timestamp); if (nothingToDelete) { @@ -162,11 +162,10 @@ private void clearPendingBulkDelete(final String prefix, final long timestamp) t if (timestamp >= storedTimestamp) { putProperties(pendingDeletesKey, deletes); S3BlobStore.log.info( - String.format("Bulk delete removed pendingDelete for for bucket '%s/%s'", bucketName, prefix)); + "Bulk delete removed pendingDelete for for bucket '%s/%s'".formatted(bucketName, prefix)); } else { - S3BlobStore.log.info(String.format( - "Bulk delete finished but there's a newer one ongoing for bucket '%s/%s'", bucketName, prefix)); + S3BlobStore.log.info("Bulk delete finished but there's a newer one ongoing for bucket '%s/%s'".formatted(bucketName, prefix)); } } catch (StorageException e) { throw new RuntimeException(e); @@ -177,8 +176,7 @@ private void clearPendingBulkDelete(final String prefix, final long timestamp) t public boolean scheduleAsyncDelete(final String prefix) throws GeoWebCacheException { final long timestamp = currentTimeSeconds(); - String msg = String.format( - "Issuing bulk delete on '%s/%s' for objects older than %d", bucketName, prefix, timestamp); + String msg = "Issuing bulk delete on '%s/%s' for objects older than %d".formatted(bucketName, prefix, timestamp); S3BlobStore.log.info(msg); Lock lock = locks.getLock(prefix); @@ -398,11 +396,10 @@ public BulkDelete( @Override public Long call() throws Exception { LockProvider.Lock lock = locks.getLock(prefix); - logger.info(String.format("Running bulk delete on '%s/%s':%d", bucketName, prefix, timestamp)); + logger.info("Running bulk delete on '%s/%s':%d".formatted(bucketName, prefix, timestamp)); try { long tilesDeleted = deleteBatchesOfTilesAndInformListeners(); - logger.info(String.format( - "Finished bulk delete on '%s/%s':%d. %d objects deleted", + logger.info("Finished bulk delete on '%s/%s':%d. %d objects deleted".formatted( bucketName, prefix, timestamp, tilesDeleted)); // Once clear of the streams, throw the interrupt exception if required @@ -473,8 +470,7 @@ private Stream boundedStreamOfS3Objects(String prefixWithoutBou private void checkInterrupted() throws InterruptedException { if (Thread.interrupted()) { - S3BlobStore.log.info(String.format( - "S3 bulk delete aborted for '%s/%s'. Will resume on next startup.", bucketName, prefix)); + S3BlobStore.log.info("S3 bulk delete aborted for '%s/%s'. Will resume on next startup.".formatted(bucketName, prefix)); throw new InterruptedException(); } } diff --git a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/BoundedS3KeySupplier.java b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/BoundedS3KeySupplier.java index 0e7dbdd82..567973bb1 100644 --- a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/BoundedS3KeySupplier.java +++ b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/BoundedS3KeySupplier.java @@ -13,8 +13,6 @@ */ package org.geowebcache.s3.streams; -import static java.lang.String.format; - import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.iterable.S3Objects; import com.amazonaws.services.s3.model.S3ObjectSummary; @@ -66,7 +64,7 @@ private synchronized S3ObjectSummary next() { } if (iterator == null && nextX <= bounds.getMaxX()) { - String prefixWithX = format("%s%d/", prefixWithoutBounds, nextX); + String prefixWithX = "%s%d/".formatted(prefixWithoutBounds, nextX); S3Objects s3Objects = S3Objects.withPrefix(conn, bucket, prefixWithX).withBatchSize(batch); iterator = s3Objects.iterator(); @@ -78,11 +76,10 @@ private synchronized S3ObjectSummary next() { if (hasNext) { count++; S3ObjectSummary summary = iterator.next(); - logger.fine(format("%s: %s", summary.getKey(), bounds)); + logger.fine("%s: %s".formatted(summary.getKey(), bounds)); return summary; } else { - logger.info(String.format( - "Exhausted objects with prefix: %s supplied %d", prefixWithoutBounds + bounds, count)); + logger.info("Exhausted objects with prefix: %s supplied %d".formatted(prefixWithoutBounds + bounds, count)); return null; } } diff --git a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/UnboundedS3KeySupplier.java b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/UnboundedS3KeySupplier.java index bf598b5ee..3e5165fa6 100644 --- a/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/UnboundedS3KeySupplier.java +++ b/geowebcache/s3storage/src/main/java/org/geowebcache/s3/streams/UnboundedS3KeySupplier.java @@ -58,7 +58,7 @@ private synchronized S3ObjectSummary next() { count++; return iterator.next(); } else { - logger.info(String.format("Exhausted objects with prefix: %s supplied %d", prefix, count)); + logger.info("Exhausted objects with prefix: %s supplied %d".formatted(prefix, count)); return null; } } diff --git a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/AbstractS3BlobStoreIntegrationTest.java b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/AbstractS3BlobStoreIntegrationTest.java index 6fecd5c53..d70b8cffe 100644 --- a/geowebcache/s3storage/src/test/java/org/geowebcache/s3/AbstractS3BlobStoreIntegrationTest.java +++ b/geowebcache/s3storage/src/test/java/org/geowebcache/s3/AbstractS3BlobStoreIntegrationTest.java @@ -442,7 +442,7 @@ private void seed( int max = (int) Math.pow(2, z); for (int x = 0; x < max; x++) { for (int y = 0; y < max; y++) { - log.fine(String.format("seeding %d,%d,%d", x, y, z)); + log.fine("seeding %d,%d,%d".formatted(x, y, z)); put(x, y, z, gridset, formatExtension, parameters); } } diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/GeoToolsMbtilesUtils.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/GeoToolsMbtilesUtils.java index c1630c9cc..4790018a2 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/GeoToolsMbtilesUtils.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/GeoToolsMbtilesUtils.java @@ -27,7 +27,7 @@ public static MBTilesFile getMBTilesFile(Connection connection, File file) { try { return new MbtilesFileExtended(connection); } catch (Exception exception) { - throw new RuntimeException(String.format("Error creating MBTiles file for '%s'.", file), exception); + throw new RuntimeException("Error creating MBTiles file for '%s'.".formatted(file), exception); } } diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesBlobStore.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesBlobStore.java index da4003ff1..1fc82d413 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesBlobStore.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesBlobStore.java @@ -129,8 +129,7 @@ public MbtilesBlobStore(MbtilesInfo configuration, SqliteConnectionManager conne initMbtilesLayersMetadata(configuration.getMbtilesMetadataDirectory()); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "MBTiles blob store initiated: [eagerDelete='%b', useCreateTime='%b'.", + LOGGER.info("MBTiles blob store initiated: [eagerDelete='%b', useCreateTime='%b'.".formatted( eagerDelete, useCreateTime)); } } @@ -143,7 +142,7 @@ private boolean tileIsGzipped(TileObject tile) throws MimeException { public void put(TileObject tile) throws StorageException { File file = fileManager.getFile(tile); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' mapped to file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' mapped to file '%s'.".formatted(tile, file)); } initDatabaseFileIfNeeded(file, tile.getLayerName(), tile.getBlobFormat()); // do work in write mode @@ -185,7 +184,7 @@ public void put(TileObject tile) throws StorageException { System.currentTimeMillis()); } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' saved in file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' saved in file '%s'.".formatted(tile, file)); } if (listeners.isEmpty()) { // no listeners to update we are done @@ -210,7 +209,7 @@ public void put(TileObject tile) throws StorageException { public boolean get(final TileObject tile) throws StorageException { File file = fileManager.getFile(tile); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' mapped to file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' mapped to file '%s'.".formatted(tile, file)); } initDatabaseFileIfNeeded(file, tile.getLayerName(), tile.getBlobFormat()); // do work in readonly mode @@ -238,7 +237,7 @@ public boolean get(final TileObject tile) throws StorageException { tile.setBlob(Utils.byteArrayToResource(bytes)); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' found on file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' found on file '%s'.".formatted(tile, file)); } return true; } @@ -246,7 +245,7 @@ public boolean get(final TileObject tile) throws StorageException { throw Utils.exception(exception, "Error loading tile '%s' from MBTiles file '%s'.", tile, file); } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' not found on file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' not found on file '%s'.".formatted(tile, file)); } return false; }); @@ -271,12 +270,12 @@ public boolean get(final TileObject tile) throws StorageException { public boolean delete(TileObject tile) throws StorageException { File file = fileManager.getFile(tile); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' mapped to file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' mapped to file '%s'.".formatted(tile, file)); } if (!file.exists()) { // database file doesn't exists so nothing to do if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Containing file '%s' for tile '%s' doesn't exists.", file, tile)); + LOGGER.fine("Containing file '%s' for tile '%s' doesn't exists.".formatted(file, tile)); } return false; } @@ -301,7 +300,7 @@ public boolean delete(TileObject tile) throws StorageException { deleteTileCreateTime(connection, tile.getXYZ()[2], tile.getXYZ()[0], tile.getXYZ()[1]); } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' deleted from file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' deleted from file '%s'.".formatted(tile, file)); } return true; } @@ -309,7 +308,7 @@ public boolean delete(TileObject tile) throws StorageException { throw Utils.exception(exception, "Error deleting tile '%s' from MBTiles file '%s'.", tile, file); } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Tile '%s' not found on file '%s'.", tile, file)); + LOGGER.fine("Tile '%s' not found on file '%s'.".formatted(tile, file)); } return false; }); @@ -324,8 +323,7 @@ public synchronized void putLayerMetadata(String layerName, String key, String v connectionManager.executeSql( metadataFile, "INSERT OR REPLACE INTO metadata VALUES (?, ?, ?);", layerName, key, value); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Metadata for layer '%s' for key '%s' inserted or updated on file '%s'.", + LOGGER.info("Metadata for layer '%s' for key '%s' inserted or updated on file '%s'.".formatted( layerName, key, metadataFile)); } } @@ -341,16 +339,14 @@ public String getLayerMetadata(String layerName, String key) { // metadata value is available String value = resultSet.getString(1); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format( - "Metadata for layer '%s' with key '%s' found '%s'.", + LOGGER.fine("Metadata for layer '%s' with key '%s' found '%s'.".formatted( layerName, key, value)); } return value; } // metadata value not found if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format( - "Metadata for layer '%s' with key '%s' not found.", layerName, key)); + LOGGER.fine("Metadata for layer '%s' with key '%s' not found.".formatted(layerName, key)); } return null; } catch (Exception exception) { @@ -364,7 +360,7 @@ public String getLayerMetadata(String layerName, String key) { // probably because the metadata table doesn't exists if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( - Level.SEVERE, String.format("Error getting metadata from file '%s'.", metadataFile), exception); + Level.SEVERE, "Error getting metadata from file '%s'.".formatted(metadataFile), exception); } return null; } @@ -426,8 +422,7 @@ public boolean delete(TileRange tileRange) throws StorageException { // current file for (long[] range : entry.getValue()) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format( - "Deleting tiles range [minx=%d, miny=%d, maxx=%d, maxxy=%d, zoom=%d] in file '%s'.", + LOGGER.fine("Deleting tiles range [minx=%d, miny=%d, maxx=%d, maxxy=%d, zoom=%d] in file '%s'.".formatted( range[0], range[1], range[2], range[3], range[4], file)); } completionService.submit( @@ -542,7 +537,7 @@ private void deleteTileCreateTime(Connection connection, long z, long x, long y) if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( Level.SEVERE, - String.format("Something bad happen when deleting create time for tile '%d-%d-%d'.", x, y, z), + "Something bad happen when deleting create time for tile '%d-%d-%d'.".formatted(x, y, z), exception); } } @@ -570,7 +565,7 @@ private Long getTileCreateTime(File file, long z, long x, long y) throws Storage if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( Level.SEVERE, - String.format("Something bad happen when querying create time for tile '%d-%d-%d'.", x, y, z), + "Something bad happen when querying create time for tile '%d-%d-%d'.".formatted(x, y, z), exception); } } @@ -662,8 +657,7 @@ private void initMbtilesLayersMetadata(String mbtilesMetadataDirectoryPath) { File mbtilesMetadataDirectory = new File(mbtilesMetadataDirectoryPath); if (!mbtilesMetadataDirectory.exists()) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Mbtiles metadata directory '%s' doesn't exists, no mbtiles metadata will be parsed.", + LOGGER.info("Mbtiles metadata directory '%s' doesn't exists, no mbtiles metadata will be parsed.".formatted( mbtilesMetadataDirectoryPath)); } return; @@ -671,8 +665,7 @@ private void initMbtilesLayersMetadata(String mbtilesMetadataDirectoryPath) { File[] files = mbtilesMetadataDirectory.listFiles(); if (files == null) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "No files present in mbtiles metadata directory '%s', no mbtiles metadata will be parsed.", + LOGGER.info("No files present in mbtiles metadata directory '%s', no mbtiles metadata will be parsed.".formatted( mbtilesMetadataDirectoryPath)); } return; @@ -701,7 +694,7 @@ private void initMbtilesLayersMetadata(String mbtilesMetadataDirectoryPath) { // index the parsed mbtiles metadata layersMetadata.put(layerName, gtMetadata); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Parsed mbtiles metadata for layer '%s'.", layerName)); + LOGGER.info("Parsed mbtiles metadata for layer '%s'.".formatted(layerName)); } } } @@ -730,7 +723,7 @@ public Map>> getParametersMapping(String la // probably because the metadata table doesn't exists if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( - Level.SEVERE, String.format("Error getting metadata from file '%s'.", metadataFile), exception); + Level.SEVERE, "Error getting metadata from file '%s'.".formatted(metadataFile), exception); } return Collections.emptyMap(); } diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesInfo.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesInfo.java index 1e07b3bca..a0dce2331 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesInfo.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/MbtilesInfo.java @@ -13,6 +13,7 @@ */ package org.geowebcache.sqlite; +import java.io.Serial; import org.geowebcache.layer.TileLayerDispatcher; import org.geowebcache.locks.LockProvider; import org.geowebcache.storage.BlobStore; @@ -20,6 +21,7 @@ /** Holder for the properties needed to configure a mbtiles blob store. */ public class MbtilesInfo extends SqliteInfo { + @Serial private static final long serialVersionUID = -6618985107587790155L; public MbtilesInfo() { diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteConnectionManager.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteConnectionManager.java index ec5e63ae9..511b59a7b 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteConnectionManager.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteConnectionManager.java @@ -50,8 +50,7 @@ public SqliteConnectionManager(SqliteInfo configuration) { SqliteConnectionManager(long poolSize, long poolReaperIntervalMs) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Initiating connection poll: [poolSize='%d', poolReaperIntervalMs='%d'].", + LOGGER.info("Initiating connection poll: [poolSize='%d', poolReaperIntervalMs='%d'].".formatted( poolSize, poolReaperIntervalMs)); } // let's load the sqlite driver @@ -67,15 +66,14 @@ public SqliteConnectionManager(SqliteInfo configuration) { new Thread(() -> { while (!stopPoolReaper) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format( - "Current pool size is '%d' and threshold is '%f'.", + LOGGER.fine("Current pool size is '%d' and threshold is '%f'.".formatted( pool.size(), poolSizeThreshold)); } if (pool.size() > poolSizeThreshold) { // we exceed the pool size threshold, time to reap the less used // connections if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Reaping connections, current pool size %d.", pool.size())); + LOGGER.info("Reaping connections, current pool size %d.".formatted(pool.size())); } List pooledConnections = new ArrayList<>(pool.values()); Collections.sort(pooledConnections); @@ -124,7 +122,7 @@ void executeSql(File file, String sql, Object... parameters) { /** Submit an SQL statement to be executed with the provided connection. */ void executeSql(Connection connection, String sql, Object... parameters) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Executing SQL '%s'.", sql)); + LOGGER.fine("Executing SQL '%s'.".formatted(sql)); } try (PreparedStatement statement = connection.prepareStatement(sql)) { for (int i = 0; i < parameters.length; i++) { @@ -146,7 +144,7 @@ T executeQuery(File file, ResultExtractor extractor, String query, Object /** Submit a query to be executed with the provided connection. */ T executeQuery(Connection connection, ResultExtractor extractor, String query, Object... parameters) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Executing query '%s'.", query)); + LOGGER.fine("Executing query '%s'.".formatted(query)); } try (PreparedStatement statement = connection.prepareStatement(query)) { for (int i = 0; i < parameters.length; i++) { @@ -170,11 +168,11 @@ void doWork(File file, boolean readOnly, Work work) { T doWork(File file, boolean readOnly, WorkWithResult work) { if (readOnly) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Starting work on file '%s' in readonly mode.", file)); + LOGGER.fine("Starting work on file '%s' in readonly mode.".formatted(file)); } } else { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Starting work on file '%s' in write mode.", file)); + LOGGER.fine("Starting work on file '%s' in write mode.".formatted(file)); } } // let's find or instantiate on the fly a pool connection for the current file @@ -197,7 +195,7 @@ T doWork(File file, boolean readOnly, WorkWithResult work) { } } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Work on file '%s' is done.", file)); + LOGGER.fine("Work on file '%s' is done.".formatted(file)); } return result; } finally { @@ -212,7 +210,7 @@ T doWork(File file, boolean readOnly, WorkWithResult work) { void replace(File currentFile, File newFile) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Replacing file '%s' with file '%s'.", currentFile, newFile)); + LOGGER.fine("Replacing file '%s' with file '%s'.".formatted(currentFile, newFile)); } PooledConnection currentPooledConnection = getPooledConnection(currentFile).getWriteLockOnValidConnection(); @@ -223,7 +221,7 @@ void replace(File currentFile, File newFile) { } FileUtils.moveFile(newFile, currentFile); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("File '%s' replaced with file '%s'.", currentFile, newFile)); + LOGGER.info("File '%s' replaced with file '%s'.".formatted(currentFile, newFile)); } } catch (Exception exception) { throw Utils.exception(exception, "Error replacing file '%s' with file '%s'.", currentFile, newFile); @@ -234,11 +232,11 @@ void replace(File currentFile, File newFile) { void delete(File file) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Deleting file '%s'.", file)); + LOGGER.fine("Deleting file '%s'.".formatted(file)); } if (!file.exists()) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("File '%s' doesn't exists.", file)); + LOGGER.fine("File '%s' doesn't exists.".formatted(file)); } return; } @@ -248,7 +246,7 @@ void delete(File file) { FileUtils.deleteQuietly(file); pool.remove(file); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("File '%s' deleted.", file)); + LOGGER.info("File '%s' deleted.".formatted(file)); } } catch (Exception exception) { throw Utils.exception(exception, "Error deleting file '%s'.", file); @@ -259,7 +257,7 @@ void delete(File file) { void rename(File currentFile, File newFile) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Renaming file '%s' to '%s'.", currentFile, newFile)); + LOGGER.fine("Renaming file '%s' to '%s'.".formatted(currentFile, newFile)); } PooledConnection pooledConnection = getPooledConnection(currentFile).getWriteLockOnValidConnection(); try { @@ -267,7 +265,7 @@ void rename(File currentFile, File newFile) { pool.remove(currentFile); FileUtils.moveFile(currentFile, newFile); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("File '%s' renamed to '%s'.", currentFile, newFile)); + LOGGER.info("File '%s' renamed to '%s'.".formatted(currentFile, newFile)); } } catch (Exception exception) { throw Utils.exception(exception, "Renaming file '%s' to '%s'.", currentFile, newFile); @@ -303,7 +301,7 @@ private PooledConnection getPooledConnection(File file) { } // creating a new pooled connection for the database file if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Creating pooled connection to file '%s'.", file)); + LOGGER.fine("Creating pooled connection to file '%s'.".formatted(file)); } pooledConnection = new PooledConnection(file); pooledConnection.getWriteLock(); @@ -312,7 +310,7 @@ private PooledConnection getPooledConnection(File file) { if (existing != null) { // someone create a pooled connection for this file in the meantime if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Connection to file '%s' already exists, closing this one.", file)); + LOGGER.fine("Connection to file '%s' already exists, closing this one.".formatted(file)); } pooledConnection.closeConnection(); return existing; @@ -370,7 +368,7 @@ void reapConnection() { pool.remove(file); releaseWriteLock(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Connection to file '%s' reaped.", file)); + LOGGER.info("Connection to file '%s' reaped.".formatted(file)); } } @@ -384,7 +382,7 @@ void closeConnection() { throw Utils.exception("Error closing connection to file '%s'.", file); } if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Connection to file '%s' closed.", file)); + LOGGER.info("Connection to file '%s' closed.".formatted(file)); } } } @@ -393,11 +391,11 @@ void getReadLock() { String logId = ""; if (LOGGER.isLoggable(Level.FINE)) { logId = UUID.randomUUID().toString(); - LOGGER.fine(String.format("[%s] Waiting for read lock on file '%s'.", logId, file)); + LOGGER.fine("[%s] Waiting for read lock on file '%s'.".formatted(logId, file)); } lock.readLock().lock(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("[%s] Read lock on file '%s' obtained.", logId, file)); + LOGGER.fine("[%s] Read lock on file '%s' obtained.".formatted(logId, file)); } } @@ -424,7 +422,7 @@ PooledConnection getReadLockOnValidConnection() { void releaseReadLock() { lock.readLock().unlock(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Read lock on file '%s' released.", file)); + LOGGER.fine("Read lock on file '%s' released.".formatted(file)); } } @@ -432,11 +430,11 @@ void getWriteLock() { String logId = ""; if (LOGGER.isLoggable(Level.FINE)) { logId = UUID.randomUUID().toString(); - LOGGER.fine(String.format("[%s] Waiting for write lock on file '%s'.", logId, file)); + LOGGER.fine("[%s] Waiting for write lock on file '%s'.".formatted(logId, file)); } lock.writeLock().lock(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("[%s] Write lock on file '%s' obtained.", logId, file)); + LOGGER.fine("[%s] Write lock on file '%s' obtained.".formatted(logId, file)); } } @@ -463,13 +461,13 @@ PooledConnection getWriteLockOnValidConnection() { void releaseWriteLock() { lock.writeLock().unlock(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Write lock on file '%s' released.", file)); + LOGGER.fine("Write lock on file '%s' released.".formatted(file)); } } private Connection openConnection(File file) { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Opening connection to file '%s'.", file)); + LOGGER.info("Opening connection to file '%s'.".formatted(file)); } Utils.createFileParents(file); try { diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteInfo.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteInfo.java index 3e4f78251..574d1d45a 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteInfo.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/SqliteInfo.java @@ -14,11 +14,13 @@ package org.geowebcache.sqlite; import java.io.File; +import java.io.Serial; import java.util.UUID; import org.geowebcache.config.BlobStoreInfo; /** Holder for the common properties needed to configure a sqlite based blob store. */ public abstract class SqliteInfo extends BlobStoreInfo { + @Serial private static final long serialVersionUID = 2300159159094621077L; public SqliteInfo() { diff --git a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/Utils.java b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/Utils.java index 01dbab92b..f73174c58 100644 --- a/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/Utils.java +++ b/geowebcache/sqlite/src/main/java/org/geowebcache/sqlite/Utils.java @@ -86,14 +86,14 @@ static void check(boolean condition, String message, Object... arguments) { @FormatMethod static RuntimeException exception(String message, Object... arguments) { - String finalMessage = String.format(message, arguments); + String finalMessage = message.formatted(arguments); LOGGER.severe(finalMessage); return new RuntimeException(finalMessage); } @FormatMethod static RuntimeException exception(Exception exception, String message, Object... arguments) { - String finalMessage = String.format(message, arguments); + String finalMessage = message.formatted(arguments); LOGGER.severe(finalMessage); return new RuntimeException(finalMessage, exception); } diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java index bed110550..be4ad7ae0 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/OperationsRestTest.java @@ -26,7 +26,6 @@ import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.List; @@ -112,7 +111,7 @@ public void testZipFileUploadReplace() throws Exception { File tempDirectory = Files.createTempDirectory("gwc-").toFile(); addFilesToDelete(tempDirectory); File zipFile = new File(tempDirectory, "replace.zip"); - zipDirectory(Paths.get(rootDirectory.getPath()), zipFile); + zipDirectory(Path.of(rootDirectory.getPath()), zipFile); try (FileInputStream zipFileInputStream = new FileInputStream(zipFile)) { // perform the rest request MockMultipartFile zipUpload = new MockMultipartFile("file", zipFileInputStream); diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java index 7b441b7a0..a2d96ee63 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java @@ -152,7 +152,7 @@ private void genericMultiThreadsTest(int threadsNumber, int workersNumber, long List>> results = new ArrayList<>(); for (int i = 0; i < workersNumber; i++) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted worker '%d'\\'%d'.", i, workersNumber)); + LOGGER.fine("Submitted worker '%d'\\'%d'.".formatted(i, workersNumber)); } executor.submit(() -> { File file = files[random.nextInt(files.length)]; @@ -216,7 +216,7 @@ public void extract(ResultSet resultSet) throws Exception { @FormatMethod private static void execute(Connection connection, String sql, Object... arguments) { - String finalSql = String.format(sql, arguments); + String finalSql = sql.formatted(arguments); try (PreparedStatement statement = connection.prepareStatement(finalSql)) { statement.execute(); } catch (Exception exception) { @@ -230,7 +230,7 @@ private abstract static class ExecuteQuery { @FormatMethod public ExecuteQuery(Connection connection, String query, Object... arguments) { - String finalQuery = String.format(query, arguments); + String finalQuery = query.formatted(arguments); try (PreparedStatement statement = connection.prepareStatement(finalQuery)) { extract(statement.executeQuery()); } catch (Exception exception) { diff --git a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java index 12b115895..3cc1ad3fb 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java @@ -50,7 +50,7 @@ public static void main(String[] args) throws Exception { // create the directory that will contain all created files File rootDirectory = Files.createTempDirectory("gwc-").toFile(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Root directory '%s'.", rootDirectory)); + LOGGER.info("Root directory '%s'.".formatted(rootDirectory)); } // seeding file system long[][] tiles = new long[TILES][3]; @@ -74,7 +74,7 @@ private static void rawSqlitle(File rootDirectory, File seedFile, long[][] tiles // creating a new database by copying the seeded one File databaseFile = new File(rootDirectory, "raw_perf_test.sqlite"); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start raw select from file '%s'.", databaseFile)); + LOGGER.info("Start raw select from file '%s'.".formatted(databaseFile)); } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks @@ -86,12 +86,12 @@ private static void rawSqlitle(File rootDirectory, File seedFile, long[][] tiles executor.submit((Runnable) () -> getTile(connection, tile)); if (i != 0 && i % 10000 == 0) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", i)); + LOGGER.fine("Submitted %d select tasks.".formatted(i)); } } } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", TILES)); + LOGGER.fine("Submitted %d select tasks.".formatted(TILES)); } // lets wait for the workers to finish executor.shutdown(); @@ -99,11 +99,10 @@ private static void rawSqlitle(File rootDirectory, File seedFile, long[][] tiles // computing some stats long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Tiles raw select time '%d'.", endTime - startTime)); + LOGGER.info("Tiles raw select time '%d'.".formatted(endTime - startTime)); } if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Tiles raw selected per second '%f'.", TILES / (float) (endTime - startTime) * 1000)); + LOGGER.info("Tiles raw selected per second '%f'.".formatted(TILES / (float) (endTime - startTime) * 1000)); } } FileUtils.deleteQuietly(databaseFile); @@ -114,7 +113,7 @@ private static void pooledSqlitle(File rootDirectory, File seedFile, long[][] ti // creating a new database by copying the seeded one File databaseFile = new File(rootDirectory, "pooled_perf_test.sqlite"); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start pooled select from file '%s'.", databaseFile)); + LOGGER.info("Start pooled select from file '%s'.".formatted(databaseFile)); } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks @@ -128,12 +127,12 @@ private static void pooledSqlitle(File rootDirectory, File seedFile, long[][] ti })); if (i != 0 && i % 10000 == 0) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", i)); + LOGGER.fine("Submitted %d select tasks.".formatted(i)); } } } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", TILES)); + LOGGER.fine("Submitted %d select tasks.".formatted(TILES)); } // lets wait for the workers to finish executor.shutdown(); @@ -141,11 +140,10 @@ private static void pooledSqlitle(File rootDirectory, File seedFile, long[][] ti // computing some stats long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Tiles pooled select time '%d'.", endTime - startTime)); + LOGGER.info("Tiles pooled select time '%d'.".formatted(endTime - startTime)); } if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Tiles pooled selected per second '%f'.", TILES / (float) (endTime - startTime) * 1000)); + LOGGER.info("Tiles pooled selected per second '%f'.".formatted(TILES / (float) (endTime - startTime) * 1000)); } // clean everything connectionManager.reapAllConnections(); @@ -159,7 +157,7 @@ private static void mbtilesStore(File rootDirectory, File seedFile, long[][] til File databaseFile = new File(rootDirectory, Utils.buildPath("grid", "layer", "image_png", "mbtiles_perf_test.sqlite")); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start mbtiles select from file '%s'.", databaseFile)); + LOGGER.info("Start mbtiles select from file '%s'.".formatted(databaseFile)); } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks @@ -185,12 +183,12 @@ private static void mbtilesStore(File rootDirectory, File seedFile, long[][] til }); if (i != 0 && i % 10000 == 0) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", i)); + LOGGER.fine("Submitted %d select tasks.".formatted(i)); } } } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d select tasks.", TILES)); + LOGGER.fine("Submitted %d select tasks.".formatted(TILES)); } // lets wait for the workers to finish executor.shutdown(); @@ -198,11 +196,10 @@ private static void mbtilesStore(File rootDirectory, File seedFile, long[][] til // computing some stats long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Tiles mbtiles blobstore select time '%d'.", endTime - startTime)); + LOGGER.info("Tiles mbtiles blobstore select time '%d'.".formatted(endTime - startTime)); } if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Tiles mbtiles blobstore selected per second '%f'.", TILES / (float) (endTime - startTime) * 1000)); + LOGGER.info("Tiles mbtiles blobstore selected per second '%f'.".formatted(TILES / (float) (endTime - startTime) * 1000)); } // clean everything connectionManager.reapAllConnections(); @@ -213,7 +210,7 @@ private static void mbtilesStore(File rootDirectory, File seedFile, long[][] til /** Retrieve the created tiles using the file blobstore. */ private static void fileStore(File seedDirectory, long[][] tiles) throws Exception { if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start reading from directory'%s'.", seedDirectory)); + LOGGER.info("Start reading from directory'%s'.".formatted(seedDirectory)); } // submitting the read tasks ExecutorService executor = Executors.newFixedThreadPool(WORKERS); @@ -232,12 +229,12 @@ private static void fileStore(File seedDirectory, long[][] tiles) throws Excepti }); if (i != 0 && i % 10000 == 0) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d read tasks.", i)); + LOGGER.fine("Submitted %d read tasks.".formatted(i)); } } } if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Submitted %d read tasks.", TILES)); + LOGGER.fine("Submitted %d read tasks.".formatted(TILES)); } // lets wait for the workers to finish executor.shutdown(); @@ -245,11 +242,10 @@ private static void fileStore(File seedDirectory, long[][] tiles) throws Excepti // computing some stats long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Tiles file blobstore read time '%d'.", endTime - startTime)); + LOGGER.info("Tiles file blobstore read time '%d'.".formatted(endTime - startTime)); } if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format( - "Tiles file blobstore reads per second '%f'.", TILES / (float) (endTime - startTime) * 1000)); + LOGGER.info("Tiles file blobstore reads per second '%f'.".formatted(TILES / (float) (endTime - startTime) * 1000)); } } @@ -258,7 +254,7 @@ private static File seedFileSystem(File rootDirectory, long[][] tiles) throws Ex // creating the root directory where tiles will be saved File seedDirectory = new File(rootDirectory, "tiles"); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start seeding file system '%s'.", seedDirectory)); + LOGGER.info("Start seeding file system '%s'.".formatted(seedDirectory)); } BlobStore fileBlobStore = new FileBlobStore(seedDirectory.getPath()); // start seeding the tiles @@ -277,13 +273,13 @@ private static File seedFileSystem(File rootDirectory, long[][] tiles) throws Ex Utils.byteArrayToResource(tile.data))); if (i != 0 && i % 10000 == 0) { if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Stored %d tiles.", i)); + LOGGER.fine("Stored %d tiles.".formatted(i)); } } } long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Insert time '%d' (batch mode).", endTime - startTime)); + LOGGER.info("Insert time '%d' (batch mode).".formatted(endTime - startTime)); } return seedDirectory; } @@ -293,7 +289,7 @@ private static File createSeedFile(File rootDirectory, long[][] tiles) throws Ex // creating the database that will be seeded File seedFile = new File(rootDirectory, "seed_perf_test.sqlite"); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Start seeding file '%s'.", seedFile)); + LOGGER.info("Start seeding file '%s'.".formatted(seedFile)); } try (Connection connection = DriverManager.getConnection("jdbc:sqlite:" + seedFile.getPath())) { String createTableSql = "CREATE TABLE IF NOT EXISTS tiles (zoom_level integer, tile_column integer, " @@ -318,13 +314,13 @@ private static File createSeedFile(File rootDirectory, long[][] tiles) throws Ex if (i != 0 && i % 10000 == 0) { statement.executeBatch(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Inserted batch %d.", i)); + LOGGER.fine("Inserted batch %d.".formatted(i)); } } } statement.executeBatch(); if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(String.format("Inserted batch %d.", TILES)); + LOGGER.fine("Inserted batch %d.".formatted(TILES)); } } catch (Exception exception) { throw Utils.exception(exception, "Error executing SQL '%s'.", sql); @@ -333,7 +329,7 @@ private static File createSeedFile(File rootDirectory, long[][] tiles) throws Ex executeSql(connection, "END TRANSACTION;"); long endTime = System.currentTimeMillis(); if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.info(String.format("Insert time '%d' (batch mode).", endTime - startTime)); + LOGGER.info("Insert time '%d' (batch mode).".formatted(endTime - startTime)); } } return seedFile; @@ -355,7 +351,7 @@ private static byte[] getTile(Connection connection, long[] xyz) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( Level.SEVERE, - String.format("Tile %d-%d-%d data is not valid.", xyz[2], xyz[0], xyz[1])); + "Tile %d-%d-%d data is not valid.".formatted(xyz[2], xyz[0], xyz[1])); } } // the tile data looks good @@ -364,7 +360,7 @@ private static byte[] getTile(Connection connection, long[] xyz) { // the tile was not found if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log( - Level.SEVERE, String.format("Failed to load tile %d-%d-%d.", xyz[2], xyz[0], xyz[1])); + Level.SEVERE, "Failed to load tile %d-%d-%d.".formatted(xyz[2], xyz[0], xyz[1])); } return null; } diff --git a/geowebcache/swiftblob/pom.xml b/geowebcache/swiftblob/pom.xml index bb52bc92d..924dfbc5c 100644 --- a/geowebcache/swiftblob/pom.xml +++ b/geowebcache/swiftblob/pom.xml @@ -22,6 +22,12 @@ gwc-core ${project.version} + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + org.apache.jclouds.api diff --git a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStore.java b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStore.java index 831c4ef37..801cc4fc1 100644 --- a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStore.java +++ b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStore.java @@ -182,7 +182,7 @@ public TileToKey(String coordsPrefix, MimeType mimeType) { @Override public String apply(long[] loc) { // String in format "//." - return String.format("%s%d/%d/%d.%s", coordsPrefix, loc[2], loc[0], loc[1], extension); + return "%s%d/%d/%d.%s".formatted(coordsPrefix, loc[2], loc[0], loc[1], extension); } } @@ -373,8 +373,8 @@ protected boolean deleteByPath(String path, IBlobStoreListenerNotifier notifier) // Cancel all pending uploads to this path for (Object task : taskQueue.toArray()) { // Only cancel uploads. Leave all existing SwiftDeletionTask objects in queue - if (task instanceof SwiftUploadTask) { - String key = ((SwiftUploadTask) task).getKey(); // path to tile image + if (task instanceof SwiftUploadTask uploadTask) { + String key = uploadTask.getKey(); // path to tile image // Cancel upload if image path will be deleted by this operation if (key.startsWith(path)) { @@ -389,7 +389,7 @@ protected boolean deleteByPath(String path, IBlobStoreListenerNotifier notifier) // Create task to delete this path and add it to the executor queue executor.execute(new SwiftDeleteTask(blobStore, path, config.getContainer(), notifier)); - log.fine(String.format("Deleting Swift tile cache at %s/%s", config.getContainer(), path)); + log.fine("Deleting Swift tile cache at %s/%s".formatted(config.getContainer(), path)); // This operation can take a long time to complete and can // lead to timeout errors for the end-user when handled as a blocking diff --git a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStoreInfo.java b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStoreInfo.java index d9faee676..0352718fb 100644 --- a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStoreInfo.java +++ b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftBlobStoreInfo.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.io.Serial; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -44,6 +45,7 @@ public class SwiftBlobStoreInfo extends BlobStoreInfo { static Logger log = Logging.getLogger(SwiftBlobStoreInfo.class.getName()); + @Serial private static final long serialVersionUID = 9072751143836460389L; private static final String provider = "openstack-swift"; @@ -164,9 +166,9 @@ public String getLocation() { String bucket = this.getContainer(); String prefix = this.getPrefix(); if (prefix == null) { - return String.format("bucket: %s", bucket); + return "bucket: %s".formatted(bucket); } else { - return String.format("bucket: %s prefix: %s", bucket, prefix); + return "bucket: %s prefix: %s".formatted(bucket, prefix); } } diff --git a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftDeleteTask.java b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftDeleteTask.java index 4c447553e..4d6ddcf81 100644 --- a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftDeleteTask.java +++ b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftDeleteTask.java @@ -64,7 +64,7 @@ public void run() { } if (deleted) { - log.info(String.format("Deleted Swift tile cache at %s/%s", container, path)); + log.info("Deleted Swift tile cache at %s/%s".formatted(container, path)); if (notifier != null) { notifier.notifyListeners(); @@ -72,8 +72,7 @@ public void run() { } else { log.log( Level.SEVERE, - String.format( - "Failed to delete Swift tile cache at %s/%s after %d retries.", container, path, RETRIES)); + "Failed to delete Swift tile cache at %s/%s after %d retries.".formatted(container, path, RETRIES)); } } } diff --git a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftTile.java b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftTile.java index af728b515..4bf8791eb 100644 --- a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftTile.java +++ b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftTile.java @@ -106,6 +106,6 @@ public void notifyListeners(BlobStoreListenerList listeners) { @Override public String toString() { String format = "%s, %s, %s, %s, xyz=%d,%d,%d"; - return String.format(format, layerName, gridSetId, blobFormat, parametersId, x, y, z); + return format.formatted(layerName, gridSetId, blobFormat, parametersId, x, y, z); } } diff --git a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftUploadTask.java b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftUploadTask.java index 61f691777..d2764d4f2 100644 --- a/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftUploadTask.java +++ b/geowebcache/swiftblob/src/main/java/org/geowebcache/swift/SwiftUploadTask.java @@ -50,8 +50,7 @@ private void checkExisted() { SwiftObject object = objectApi.getWithoutBody(key); if (log.isLoggable(Level.FINE)) { - log.fine(String.format( - logStr, + log.fine(logStr.formatted( time.format(DateTimeFormatter.ISO_DATE_TIME), "HEAD", (System.nanoTime() - getWithoutBody) / 1000000)); @@ -85,8 +84,7 @@ public void run() { objectApi.put(key, payload); if (log.isLoggable(Level.FINE)) { - log.fine(String.format( - localLogStr, + log.fine(localLogStr.formatted( time.format(DateTimeFormatter.ISO_DATE_TIME), "PUT", (System.nanoTime() - upload) / 1000000, @@ -94,7 +92,7 @@ public void run() { } tile.notifyListeners(listeners); } catch (HttpResponseException e) { - log.warning(String.format("Swift tile upload failed: %s", e.getMessage())); + log.warning("Swift tile upload failed: %s".formatted(e.getMessage())); } catch (IOException e) { // pass } diff --git a/geowebcache/web/src/test/java/org/geowebcache/jetty/HttpClientRule.java b/geowebcache/web/src/test/java/org/geowebcache/jetty/HttpClientRule.java index 614c4f5ac..ba619629c 100644 --- a/geowebcache/web/src/test/java/org/geowebcache/jetty/HttpClientRule.java +++ b/geowebcache/web/src/test/java/org/geowebcache/jetty/HttpClientRule.java @@ -77,7 +77,7 @@ public String getName() { @Override public String toString() { - return String.format("HttpClientRule[%s]", name); + return "HttpClientRule[%s]".formatted(name); } public static HttpClientRule anonymous(String clientName) { diff --git a/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java b/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java index 5346f7d64..5336092ed 100644 --- a/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java +++ b/geowebcache/web/src/test/java/org/geowebcache/jetty/RestIntegrationTest.java @@ -91,41 +91,42 @@ public void setUp() throws Exception { nsContext.bindNamespaceUri("ows", "http://www.opengis.net/ows/1.1"); // Reset Server configuration - final String globalUpdate = "\n" - + " \n" - + " GeoWebCache\n" - + " GeoWebCache is an advanced tile cache for WMS servers. It supports a large variety of protocols and\n" - + " formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.\n" - + " \n" - + " WMS\n" - + " WFS\n" - + " WMTS\n" - + " GEOWEBCACHE\n" - + " \n" - + " \n" - + " John Smith inc.\n" - + " http://www.example.com/\n" - + " \n" - + " John Smith\n" - + " Geospatial Expert\n" - + " Work\n" - + " 1 Bumpy St.\n" - + " Hobart\n" - + " TAS\n" - + " 7005\n" - + " Australia\n" - + " +61 3 0000 0000\n" - + " +61 3 0000 0001\n" - + " john.smith@example.com\n" - + " \n" - + " \n" - + " NONE\n" - + " NONE\n" - + " \n" - + " true\n" - + " false\n" - + " 120\n" - + ""; + final String globalUpdate = """ + + + GeoWebCache + GeoWebCache is an advanced tile cache for WMS servers. It supports a large variety of protocols and + formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth. + + WMS + WFS + WMTS + GEOWEBCACHE + + + John Smith inc. + http://www.example.com/ + + John Smith + Geospatial Expert + Work + 1 Bumpy St. + Hobart + TAS + 7005 + Australia + +61 3 0000 0000 + +61 3 0000 0001 + john.smith@example.com + + + NONE + NONE + + true + false + 120 + """; try (CloseableHttpResponse response = handlePut(URI.create("/geowebcache/rest/global"), admin.getClient(), globalUpdate)) { @@ -202,40 +203,41 @@ public void testGetGlobal() throws Exception { @Test public void testPutGlobal() throws Exception { - final String globalUpdate = "\n" - + " \n" - + " GeoWebCache\n" - + " GeoWebCache is an advanced tile cache for WMS servers. It supports a large variety of protocols and\n" - + " formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth.\n" - + " \n" - + " WMS\n" - + " WMTS\n" - + " GEOWEBCACHE\n" - + " \n" - + " \n" - + " Jane Doe inc.\n" - + " http://www.example.com/\n" - + " \n" - + " Jane Doe\n" - + " Geospatial Expert\n" - + " Work\n" - + " 1 Bumpy St.\n" - + " Hobart\n" - + " TAS\n" - + " 7005\n" - + " Australia\n" - + " +61 3 0000 0000\n" - + " +61 3 0000 0001\n" - + " jane.doe@example.com\n" - + " \n" - + " \n" - + " NONE\n" - + " NONE\n" - + " \n" - + " false\n" - + " false\n" - + " 120\n" - + ""; + final String globalUpdate = """ + + + GeoWebCache + GeoWebCache is an advanced tile cache for WMS servers. It supports a large variety of protocols and + formats, including WMS-C, WMTS, KML, Google Maps and Virtual Earth. + + WMS + WMTS + GEOWEBCACHE + + + Jane Doe inc. + http://www.example.com/ + + Jane Doe + Geospatial Expert + Work + 1 Bumpy St. + Hobart + TAS + 7005 + Australia + +61 3 0000 0000 + +61 3 0000 0001 + jane.doe@example.com + + + NONE + NONE + + false + false + 120 + """; testGetGlobal(); @@ -683,12 +685,13 @@ public void testGetBlobStoreJSON() throws Exception { @Test public void testPutBlobStoreCreateModifyDelete() throws Exception { - String blobStore = "\n" - + " newCache\n" - + " false\n" - + " /tmp/newCache\n" - + " 4096\n" - + ""; + String blobStore = """ + + newCache + false + /tmp/newCache + 4096 + """; // Make it sure doesn't exist try (CloseableHttpResponse response = @@ -713,12 +716,13 @@ public void testPutBlobStoreCreateModifyDelete() throws Exception { assertThat(doc, hasXPath("//fileSystemBlockSize", equalTo("4096"))); } - String blobStoreUpdate = "\n" - + " newCache\n" - + " false\n" - + " /tmp/newCache\n" - + " 2048\n" - + ""; + String blobStoreUpdate = """ + + newCache + false + /tmp/newCache + 2048 + """; try (CloseableHttpResponse response = handlePut(URI.create("/geowebcache/rest/blobstores/newCache"), admin.getClient(), blobStoreUpdate)) { @@ -826,39 +830,40 @@ public void testGetGridSetJSON() throws Exception { @Test public void testPutGridSetCreateModifyDelete() throws Exception { - String gridSet = "\n" - + "\n" - + " testGridset\n" - + " \n" - + " 4326\n" - + " \n" - + " \n" - + " \n" - + " -2495667.977678598\n" - + " -2223677.196231552\n" - + " 3291070.6104286816\n" - + " 959189.3312465074\n" - + " \n" - + " \n" - + " false\n" - + " \n" - + " 2.5E7\n" - + " 1000000.0\n" - + " 100000.0\n" - + " 25000.0\n" - + " \n" - + " 1.0\n" - + " 2.8E-4\n" - + " \n" - + " EPSG:4326:0\n" - + " EPSG:4326:1\n" - + " EPSG:4326:2\n" - + " EPSG:4326:3\n" - + " \n" - + " 211\n" - + " 211\n" - + " false\n" - + ""; + String gridSet = """ + + + testGridset + + 4326 + + + + -2495667.977678598 + -2223677.196231552 + 3291070.6104286816 + 959189.3312465074 + + + false + + 2.5E7 + 1000000.0 + 100000.0 + 25000.0 + + 1.0 + 2.8E-4 + + EPSG:4326:0 + EPSG:4326:1 + EPSG:4326:2 + EPSG:4326:3 + + 211 + 211 + false + """; // Make it sure doesn't exist try (CloseableHttpResponse response = @@ -887,39 +892,40 @@ public void testPutGridSetCreateModifyDelete() throws Exception { assertThat(doc, hasXPath("//tileHeight", equalTo("211"))); } - String gridSetUpdate = "\n" - + "\n" - + " testGridset\n" - + " \n" - + " 2163\n" - + " \n" - + " \n" - + " \n" - + " -2495667.977678598\n" - + " -2223677.196231552\n" - + " 3291070.6104286816\n" - + " 959189.3312465074\n" - + " \n" - + " \n" - + " false\n" - + " \n" - + " 2.5E7\n" - + " 1000000.0\n" - + " 100000.0\n" - + " 25000.0\n" - + " \n" - + " 1.0\n" - + " 2.8E-4\n" - + " \n" - + " EPSG:2163:0\n" - + " EPSG:2163:1\n" - + " EPSG:2163:2\n" - + " EPSG:2163:3\n" - + " \n" - + " 200\n" - + " 200\n" - + " false\n" - + ""; + String gridSetUpdate = """ + + + testGridset + + 2163 + + + + -2495667.977678598 + -2223677.196231552 + 3291070.6104286816 + 959189.3312465074 + + + false + + 2.5E7 + 1000000.0 + 100000.0 + 25000.0 + + 1.0 + 2.8E-4 + + EPSG:2163:0 + EPSG:2163:1 + EPSG:2163:2 + EPSG:2163:3 + + 200 + 200 + false + """; try (CloseableHttpResponse response = handlePut(URI.create("/geowebcache/rest/gridsets/testGridset"), admin.getClient(), gridSetUpdate)) { @@ -980,16 +986,16 @@ public void testDiskQuotaJson() throws Exception { if (response.getStatusLine().getStatusCode() == 200) { JSONObject jsonObject = getResponseEntityAsJSONObject(response); Object obj = jsonObject.get("org.geowebcache.diskquota.DiskQuotaConfig"); - if (obj instanceof JSONObject) { - assertEquals(false, ((JSONObject) obj).get("enabled")); - assertEquals(10, ((JSONObject) obj).get("cacheCleanUpFrequency")); - assertEquals("SECONDS", ((JSONObject) obj).get("cacheCleanUpUnits")); - assertEquals(2, ((JSONObject) obj).get("maxConcurrentCleanUps")); - assertEquals("LFU", ((JSONObject) obj).get("globalExpirationPolicyName")); - Object globalQuota = ((JSONObject) obj).get("globalQuota"); - if (globalQuota instanceof JSONObject) { - assertEquals(0, ((JSONObject) globalQuota).get("id")); - assertEquals(524288000, ((JSONObject) globalQuota).get("bytes")); + if (obj instanceof JSONObject object1) { + assertEquals(false, object1.get("enabled")); + assertEquals(10, object1.get("cacheCleanUpFrequency")); + assertEquals("SECONDS", object1.get("cacheCleanUpUnits")); + assertEquals(2, object1.get("maxConcurrentCleanUps")); + assertEquals("LFU", object1.get("globalExpirationPolicyName")); + Object globalQuota = object1.get("globalQuota"); + if (globalQuota instanceof JSONObject object) { + assertEquals(0, object.get("id")); + assertEquals(524288000, object.get("bytes")); } } } diff --git a/geowebcache/wms/src/main/java/org/geowebcache/config/wms/parameters/NaiveWMSDimensionFilter.java b/geowebcache/wms/src/main/java/org/geowebcache/config/wms/parameters/NaiveWMSDimensionFilter.java index da845734c..bd1a3d429 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/config/wms/parameters/NaiveWMSDimensionFilter.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/config/wms/parameters/NaiveWMSDimensionFilter.java @@ -14,6 +14,7 @@ package org.geowebcache.config.wms.parameters; import com.google.common.base.Preconditions; +import java.io.Serial; import java.util.List; import java.util.Objects; import org.geotools.ows.wms.xml.Dimension; @@ -30,6 +31,7 @@ */ public class NaiveWMSDimensionFilter extends ParameterFilter implements WMSDimensionProvider { + @Serial private static final long serialVersionUID = 8217550988333856916L; private Dimension dimension; @@ -85,9 +87,9 @@ public void appendExtentElement(StringBuilder str, String indent) { @Override public boolean equals(Object o) { - return ((o instanceof NaiveWMSDimensionFilter) && super.equals(o)) - && equals(dimension, ((NaiveWMSDimensionFilter) o).dimension) - && equals(extent, ((NaiveWMSDimensionFilter) o).extent); + return ((o instanceof NaiveWMSDimensionFilter nwmsdf) && super.equals(o)) + && equals(dimension, nwmsdf.dimension) + && equals(extent, nwmsdf.extent); } @Override diff --git a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageDecoderImpl.java b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageDecoderImpl.java index 5d513df97..b9259179d 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageDecoderImpl.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageDecoderImpl.java @@ -125,9 +125,9 @@ public BufferedImage decode(Object source, boolean aggressiveInputStreamOptimiza ImageInputStream stream = null; try { // NOPMD (handling of stream is complicated) reader = newSpi.createReaderInstance(); - if (source instanceof FileResource) { + if (source instanceof FileResource resource) { // file - stream = new FileImageInputStreamExtImpl(((FileResource) source).getFile()); + stream = new FileImageInputStreamExtImpl(resource.getFile()); // Image reading reader.setInput(stream); return reader.read(0); @@ -137,12 +137,12 @@ public BufferedImage decode(Object source, boolean aggressiveInputStreamOptimiza } // Check if the input object is an InputStream - if (source instanceof InputStream) { + if (source instanceof InputStream inputStream) { // Use of the ImageInputStreamAdapter if (isAggressiveInputStreamSupported()) { - stream = new ImageInputStreamAdapter((InputStream) source); + stream = new ImageInputStreamAdapter(inputStream); } else { - stream = new MemoryCacheImageInputStream((InputStream) source); + stream = new MemoryCacheImageInputStream(inputStream); } // Image reading diff --git a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageEncoderImpl.java b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageEncoderImpl.java index 167ae7279..c54c5130f 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageEncoderImpl.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/ImageEncoderImpl.java @@ -113,8 +113,7 @@ protected ImageWriteParam prepareParameters( params.setCompressionQuality(compressionRate); } // If JPEGWriteParams, additional parameters are set - if (params instanceof JPEGImageWriteParam) { - final JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) params; + if (params instanceof JPEGImageWriteParam jpegParams) { jpegParams.setOptimizeHuffmanTables(true); try { jpegParams.setProgressiveMode(JPEGImageWriteParam.MODE_DEFAULT); @@ -248,12 +247,12 @@ public void encode( try { // NOPMD (complex instantiation of the image stream writer = newSpi.createWriterInstance(); // Check if the input object is an OutputStream - if (destination instanceof OutputStream) { + if (destination instanceof OutputStream outputStream) { // Use of the ImageOutputStreamAdapter if (isAggressiveOutputStreamSupported()) { - stream = new ImageOutputStreamAdapter((OutputStream) destination); + stream = new ImageOutputStreamAdapter(outputStream); } else { - stream = new MemoryCacheImageOutputStream((OutputStream) destination); + stream = new MemoryCacheImageOutputStream(outputStream); } // Preparation of the ImageWriteParams diff --git a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/PNGImageEncoder.java b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/PNGImageEncoder.java index deae9534c..38c63fbb2 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/io/codec/PNGImageEncoder.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/io/codec/PNGImageEncoder.java @@ -102,7 +102,7 @@ public void encode( OutputStream stream = null; try { // NOPMD stream not instantiated here // Check if the input object is an OutputStream - if (destination instanceof OutputStream) { + if (destination instanceof OutputStream outputStream) { boolean isScanlinePresent = writer.isScanlineSupported(image); if (!isScanlinePresent) { image = new ImageWorker(image) @@ -120,7 +120,7 @@ public void encode( } else { filter = (FilterType) filterObj; } - stream = (OutputStream) destination; + stream = outputStream; // Image preparation if an image helper is present WriteHelper helper = getHelper(); diff --git a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSGetCapabilities.java b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSGetCapabilities.java index ef64e2bd1..b920d650b 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSGetCapabilities.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSGetCapabilities.java @@ -542,9 +542,9 @@ private void capabilityLayerInner(XMLBuilder xml, TileLayer layer) throws GeoWeb StringBuilder dims = new StringBuilder(); StringBuilder extents = new StringBuilder(); for (ParameterFilter parameterFilter : layer.getParameterFilters()) { - if (parameterFilter instanceof WMSDimensionProvider) { - ((WMSDimensionProvider) parameterFilter).appendDimensionElement(dims, " "); - ((WMSDimensionProvider) parameterFilter).appendExtentElement(extents, " "); + if (parameterFilter instanceof WMSDimensionProvider provider) { + provider.appendDimensionElement(dims, " "); + provider.appendExtentElement(extents, " "); } } diff --git a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSService.java b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSService.java index 1505f1421..b12677808 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSService.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSService.java @@ -311,8 +311,8 @@ public void handleRequest(Conveyor conv) throws GeoWebCacheException { throw new GeoWebCacheException(tile.getLayerId() + " is unknown."); } - if (tl instanceof ProxyLayer) { - ((ProxyLayer) tl).proxyRequest(tile); + if (tl instanceof ProxyLayer layer) { + layer.proxyRequest(tile); } else { throw new GeoWebCacheException(tile.getLayerId() + " cannot cascade WMS requests."); } @@ -433,8 +433,8 @@ public void setFullWMS(String trueFalse) { // Selection of the TileLayerConfiguration file associated to geowebcache.xml ServerConfiguration gwcXMLconfig = null; for (BaseConfiguration config : configs) { - if (config instanceof XMLConfiguration) { - gwcXMLconfig = (ServerConfiguration) config; + if (config instanceof ServerConfiguration configuration) { + gwcXMLconfig = configuration; break; } } diff --git a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSTileFuser.java b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSTileFuser.java index 96692eafb..41bee0b17 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSTileFuser.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/service/wms/WMSTileFuser.java @@ -445,8 +445,7 @@ protected void createCanvas() { Color bgColor = null; boolean transparent = true; - if (layer instanceof WMSLayer) { - WMSLayer wmsLayer = (WMSLayer) layer; + if (layer instanceof WMSLayer wmsLayer) { int[] colorAr = wmsLayer.getBackgroundColor(); if (colorAr != null) { diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java index cdb9c46ae..876317538 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesGridSetConfigurationConformanceTest.java @@ -134,9 +134,9 @@ protected Matcher infoEquals(GridSet expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && ((GridSet) item).getName().equals(expected.getName()) - && ((GridSet) item).getDescription().equals(expected.getDescription()); + return item instanceof GridSet gs + && gs.getName().equals(expected.getName()) + && gs.getDescription().equals(expected.getDescription()); } }; } @@ -147,8 +147,8 @@ protected Matcher infoEquals(int expected) { @Override public boolean matches(Object item) { - return item instanceof GridSet - && Objects.equals(((GridSet) item).getDescription(), Integer.toString(expected)); + return item instanceof GridSet gs + && Objects.equals(gs.getDescription(), Integer.toString(expected)); } }; } diff --git a/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSGetCapabilities.java b/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSGetCapabilities.java index e391d15f1..72d9a7b3d 100644 --- a/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSGetCapabilities.java +++ b/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSGetCapabilities.java @@ -734,9 +734,8 @@ private void layerResourceUrls(XMLBuilder xml, TileLayer layer, List formatExtensions = WMTSUtils.getLayerFormatsExtensions(layer); - TileJSONProvider provider = (TileJSONProvider) layer; String outputFormat = ApplicationMime.json.getFormat(); if (provider.supportsTileJSON()) { for (String tileJsonFormat : formatExtensions) { diff --git a/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSService.java b/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSService.java index a2af618a7..f5095a6eb 100644 --- a/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSService.java +++ b/geowebcache/wmts/src/main/java/org/geowebcache/service/wmts/WMTSService.java @@ -371,7 +371,7 @@ public Conveyor getKvpConveyor(HttpServletRequest request, HttpServletResponse r // we implement all WMTS supported request, this means that the provided request name is // invalid throw new OWSException( - 400, "InvalidParameterValue", "request", String.format("Invalid request name '%s'.", req)); + 400, "InvalidParameterValue", "request", "Invalid request name '%s'.".formatted(req)); } } @@ -592,12 +592,12 @@ public void handleRequest(Conveyor conv) throws OWSException, GeoWebCacheExcepti style = hint.substring(styleIndex + STYLE_HINT.length()); } - if (layer instanceof TileJSONProvider) { + if (layer instanceof TileJSONProvider provider) { // in GetCapabilities we are adding a TileJSON resource URL // only when the layer supports TileJSON. // That information allows us to return a 404 when // someone is asking a TileJSON when not supported. - if (!((TileJSONProvider) layer).supportsTileJSON()) { + if (!provider.supportsTileJSON()) { throw new HttpErrorCodeException(404, "TileJSON Not supported"); } WMTSTileJSON wmtsTileJSON = new WMTSTileJSON(convTile, servletBase, context, style, urlMangler); @@ -718,8 +718,7 @@ private static void validateWmtsServiceName(String pathServiceName, HttpServletR 400, "InvalidParameterValue", "service", - String.format( - "URL path service '%s' don't match the requested service '%s'.", + "URL path service '%s' don't match the requested service '%s'.".formatted( pathServiceName, requestedServiceName)); } } diff --git a/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSRestTest.java b/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSRestTest.java index ede5d66c1..95fa0e809 100644 --- a/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSRestTest.java +++ b/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSRestTest.java @@ -250,8 +250,8 @@ public MockHttpServletResponse dispatch(MockHttpServletRequest req) throws Excep throw new OWSException( 400, "InvalidParameterValue", "LAYERS", "Layer '" + layerName + "' is disabled"); } - if (conveyor instanceof ConveyorTile) { - ((ConveyorTile) conveyor).setTileLayer(layer); + if (conveyor instanceof ConveyorTile tile) { + tile.setTileLayer(layer); } } wmtsService.handleRequest(conveyor); From 8ab504d44ba36f829e934e745092182bcb781c4f Mon Sep 17 00:00:00 2001 From: Gabriel Roldan Date: Thu, 12 Jun 2025 00:41:52 -0300 Subject: [PATCH 2/4] lint --- geowebcache/azureblob/pom.xml | 12 +++---- .../org/geowebcache/azure/DeleteManager.java | 31 +++++++++-------- geowebcache/core/pom.xml | 12 +++---- .../geowebcache/config/XMLConfiguration.java | 34 ++++++++++--------- .../main/java/org/geowebcache/demo/Demo.java | 30 ++++++++++------ .../CaseNormalizingParameterFilter.java | 1 + .../geowebcache/storage/MetastoreRemover.java | 3 +- ...tsConfigurationGridsetConformanceTest.java | 3 +- ...MLConfigurationGridsetConformanceTest.java | 3 +- .../parameters/FloatParameterFilterTest.java | 3 +- .../IntegerParameterFilterTest.java | 3 +- .../parameters/RegexParameterFilterTest.java | 9 +++-- .../parameters/StringParameterFilterTest.java | 9 +++-- .../org/geowebcache/util/FileMatchers.java | 3 +- .../geowebcache/util/MockWMSLayerSource.java | 3 +- .../geowebcache/georss/GeoRSSPollTask.java | 5 +-- .../geowebcache/service/kml/KMLSiteMap.java | 6 ++-- .../rest/controller/BlobStoreController.java | 8 ++--- .../geowebcache/rest/service/FormService.java | 3 +- .../filter/FilterUpdateControllerTest.java | 3 +- .../rest/service/FormServiceTest.java | 4 ++- geowebcache/s3storage/pom.xml | 12 +++---- .../main/java/org/geowebcache/s3/S3Ops.java | 13 ++++--- .../geowebcache/sqlite/MbtilesBlobStore.java | 33 +++++++++--------- .../sqlite/SqliteConnectionManager.java | 8 ++--- .../org/geowebcache/sqlite/SqlitlePerf.java | 18 +++++----- geowebcache/swiftblob/pom.xml | 12 +++---- .../jetty/RestIntegrationTest.java | 18 ++++++---- .../geowebcache/service/wms/WMSService.java | 1 - ...esGridSetConfigurationConformanceTest.java | 3 +- .../geowebcache/service/wmts/WMTSService.java | 4 +-- 31 files changed, 173 insertions(+), 137 deletions(-) diff --git a/geowebcache/azureblob/pom.xml b/geowebcache/azureblob/pom.xml index 34d97d953..6843a504b 100644 --- a/geowebcache/azureblob/pom.xml +++ b/geowebcache/azureblob/pom.xml @@ -37,12 +37,12 @@ gwc-core ${project.version} - - jakarta.annotation - jakarta.annotation-api - 1.3.5 - provided - + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + com.azure diff --git a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java index 3f313214f..f3be93cff 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/DeleteManager.java @@ -118,8 +118,8 @@ public Long deleteParallel(List keys) throws StorageException { public boolean scheduleAsyncDelete(final String prefix) throws StorageException { final long timestamp = currentTimeSeconds(); - String msg = "Issuing bulk delete on '%s/%s' for objects older than %d".formatted( - client.getContainerName(), prefix, timestamp); + String msg = "Issuing bulk delete on '%s/%s' for objects older than %d" + .formatted(client.getContainerName(), prefix, timestamp); log.info(msg); try { @@ -158,8 +158,8 @@ public void issuePendingBulkDeletes() throws StorageException { final String prefix = e.getKey().toString(); final long timestamp = Long.parseLong(e.getValue().toString()); if (log.isLoggable(Level.INFO)) - log.info("Restarting pending bulk delete on '%s/%s':%d".formatted( - client.getContainerName(), prefix, timestamp)); + log.info("Restarting pending bulk delete on '%s/%s':%d" + .formatted(client.getContainerName(), prefix, timestamp)); if (!asyncDelete(prefix, timestamp)) { deletesToClear.add(prefix); } @@ -217,7 +217,8 @@ public Long call() throws Exception { try { checkInterrupted(); if (log.isLoggable(Level.INFO)) - log.info("Running bulk delete on '%s/%s':%d".formatted(client.getContainerName(), prefix, timestamp)); + log.info("Running bulk delete on '%s/%s':%d" + .formatted(client.getContainerName(), prefix, timestamp)); BlobContainerClient container = client.getContainer(); @@ -235,21 +236,21 @@ public Long call() throws Exception { } } } catch (InterruptedException | IllegalStateException e) { - log.info("Azure bulk delete aborted for '%s/%s'. Will resume on next startup.".formatted( - client.getContainerName(), prefix)); + log.info("Azure bulk delete aborted for '%s/%s'. Will resume on next startup." + .formatted(client.getContainerName(), prefix)); throw e; } catch (RuntimeException e) { log.log( Level.WARNING, - "Unknown error performing bulk Azure blobs delete of '%s/%s'".formatted( - client.getContainerName(), prefix), + "Unknown error performing bulk Azure blobs delete of '%s/%s'" + .formatted(client.getContainerName(), prefix), e); throw e; } if (log.isLoggable(Level.INFO)) - log.info("Finished bulk delete on '%s/%s':%d. %d objects deleted".formatted( - client.getContainerName(), prefix, timestamp, count)); + log.info("Finished bulk delete on '%s/%s':%d. %d objects deleted" + .formatted(client.getContainerName(), prefix, timestamp, count)); clearPendingBulkDelete(prefix, timestamp); return count; @@ -280,8 +281,8 @@ private void clearPendingBulkDelete(final String prefix, final long timestamp) t if (timestamp >= storedTimestamp) { client.putProperties(pendingDeletesKey, deletes); } else if (log.isLoggable(Level.INFO)) { - log.info("bulk delete finished but there's a newer one ongoing for container '%s/%s'".formatted( - client.getContainerName(), prefix)); + log.info("bulk delete finished but there's a newer one ongoing for container '%s/%s'" + .formatted(client.getContainerName(), prefix)); } } catch (StorageException e) { throw new UncheckedIOException(e); @@ -322,8 +323,8 @@ public Long call() throws Exception { try { checkInterrupted(); if (log.isLoggable(Level.FINER)) { - log.finer("Running delete delete on list of items on '%s':%s ... (only the first 100 items listed)".formatted( - client.getContainerName(), keys.subList(0, Math.min(keys.size(), 100)))); + log.finer("Running delete delete on list of items on '%s':%s ... (only the first 100 items listed)" + .formatted(client.getContainerName(), keys.subList(0, Math.min(keys.size(), 100)))); } BlobContainerClient container = client.getContainer(); diff --git a/geowebcache/core/pom.xml b/geowebcache/core/pom.xml index 97144eb25..7871f1ba1 100644 --- a/geowebcache/core/pom.xml +++ b/geowebcache/core/pom.xml @@ -105,12 +105,12 @@ org.springframework spring-webmvc - - jakarta.annotation - jakarta.annotation-api - 1.3.5 - provided - + + jakarta.annotation + jakarta.annotation-api + 1.3.5 + provided + org.springframework spring-jdbc diff --git a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java index a5d194f7a..c45a41964 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java @@ -431,8 +431,7 @@ public static XStream getConfiguredXStreamWithContext( if (extension instanceof ContextualConfigurationProvider provider && // Check if the context is applicable for the provider - (providerContext == null - || !provider.appliesTo(providerContext))) { + (providerContext == null || !provider.appliesTo(providerContext))) { // If so, try the next one continue; } @@ -957,7 +956,9 @@ public synchronized void addBlobStore(BlobStoreInfo info) { } // ensure there isn't a BlobStoreInfo with the same name already if (getBlobStoreNames().contains(info.getName())) { - throw new IllegalArgumentException("Failed to add BlobStoreInfo. A BlobStoreInfo with name \"%s\" already exists".formatted(info.getName())); + throw new IllegalArgumentException( + "Failed to add BlobStoreInfo. A BlobStoreInfo with name \"%s\" already exists" + .formatted(info.getName())); } // add the BlobStoreInfo final List blobStores = getGwcConfig().getBlobStores(); @@ -978,8 +979,7 @@ public synchronized void addBlobStore(BlobStoreInfo info) { if (ExceptionUtils.isOrSuppresses(e, UnsuitableStorageException.class)) { // Can't store here, roll back blobStores.remove(info); - throw new ConfigurationPersistenceException( - "Unable to add BlobStoreInfo \"%s\"".formatted(info), e); + throw new ConfigurationPersistenceException("Unable to add BlobStoreInfo \"%s\"".formatted(info), e); } throw new ConfigurationPersistenceException(e); } @@ -990,7 +990,9 @@ public synchronized void addBlobStore(BlobStoreInfo info) { public synchronized void removeBlobStore(String name) { // ensure there is a BlobStoreInfo with the name final BlobStoreInfo infoToRemove = getBlobStore(name) - .orElseThrow(() -> new NoSuchElementException("Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted(name))); + .orElseThrow(() -> new NoSuchElementException( + "Failed to remove BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist." + .formatted(name))); // remove the BlobStoreInfo final List blobStores = getGwcConfig().getBlobStores(); blobStores.remove(infoToRemove); @@ -1000,8 +1002,7 @@ public synchronized void removeBlobStore(String name) { } catch (IOException ioe) { // save failed, roll back the delete blobStores.add(infoToRemove); - throw new ConfigurationPersistenceException( - "Unable to remove BlobStoreInfo \"%s\"".formatted(name), ioe); + throw new ConfigurationPersistenceException("Unable to remove BlobStoreInfo \"%s\"".formatted(name), ioe); } try { blobStoreListeners.safeForEach(listener -> { @@ -1021,8 +1022,9 @@ public synchronized void modifyBlobStore(BlobStoreInfo info) { // ensure there is a BlobStoreInfo with the name final Optional optionalInfo = getBlobStore(info.getName()); if (optionalInfo.isEmpty()) { - throw new NoSuchElementException("Failed to modify BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist.".formatted( - info.getName())); + throw new NoSuchElementException( + "Failed to modify BlobStoreInfo. A BlobStoreInfo with name \"%s\" does not exist." + .formatted(info.getName())); } // remove existing and add the new one final List blobStores = getGwcConfig().getBlobStores(); @@ -1048,8 +1050,7 @@ public synchronized void modifyBlobStore(BlobStoreInfo info) { // Can't store here, roll back blobStores.remove(info); blobStores.add(infoToRemove); - throw new ConfigurationPersistenceException( - "Unable to modify BlobStoreInfo \"%s\"".formatted(info), e); + throw new ConfigurationPersistenceException("Unable to modify BlobStoreInfo \"%s\"".formatted(info), e); } throw new ConfigurationPersistenceException(e); } @@ -1150,8 +1151,9 @@ public void renameBlobStore(String oldName, String newName) if (blobStoreInfoToRevert == null) { // we're really messed up now as we couldn't find the BlobStoreInfo that was just // renamed. - throw new ConfigurationPersistenceException("Error reverting BlobStoreInfo modification. Could not revert rename from \"%s\" to \"%s\"".formatted( - oldName, newName)); + throw new ConfigurationPersistenceException( + "Error reverting BlobStoreInfo modification. Could not revert rename from \"%s\" to \"%s\"" + .formatted(oldName, newName)); } // revert the name and add it back to the list blobStoreInfoToRevert.setName(oldName); @@ -1165,8 +1167,8 @@ public void renameBlobStore(String oldName, String newName) }); } catch (IOException | GeoWebCacheException e) { throw new ConfigurationPersistenceException( - "Exception while handling listeners for renaming blobstore \"%s\" to \"%s\"".formatted( - oldName, newName), + "Exception while handling listeners for renaming blobstore \"%s\" to \"%s\"" + .formatted(oldName, newName), e); } } diff --git a/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java b/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java index fc8b1303c..ea04d93fe 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java +++ b/geowebcache/core/src/main/java/org/geowebcache/demo/Demo.java @@ -129,7 +129,8 @@ private static String generateHTML(TileLayerDispatcher tileLayerDispatcher, Grid buf.append(ServletUtils.gwcHtmlHeader("", "GWC Demos")); buf.append("\n"); buf.append(ServletUtils.gwcHtmlLogoLink("")); - buf.append(""" + buf.append( + """ @@ -141,7 +142,8 @@ private static String generateHTML(TileLayerDispatcher tileLayerDispatcher, Grid buf.append("
    Layer name: Enabled:
    \n"); buf.append("
    "); - buf.append(""" + buf.append( + """ These are just quick demos. GeoWebCache also supports:
    • WMTS, TMS, Virtual Earth and Google Maps
    • Proxying GetFeatureInfo, GetLegend and other WMS requests
    • @@ -158,7 +160,8 @@
    • RESTful interface for seeding and configuration (beta)
    • \ \ \ @@ -230,10 +233,15 @@ private static void outputKMLSupport(StringBuffer buf, TileLayer layer) { .filter(type -> type instanceof ImageMime || XMLMime.kml.equals(type) || XMLMime.kmz.equals(type)) .map(type -> { if (XMLMime.kmz.equals(type)) { - return "kmz".formatted(prefix, escapeHtml4(layer.getName())); + return "kmz" + .formatted(prefix, escapeHtml4(layer.getName())); } else { - return "%s".formatted( - prefix, escapeHtml4(layer.getName()), type.getFileExtension(), type.getFileExtension()); + return "%s" + .formatted( + prefix, + escapeHtml4(layer.getName()), + type.getFileExtension(), + type.getFileExtension()); } }) .collect(Collectors.joining(", "))); @@ -242,8 +250,8 @@ private static void outputKMLSupport(StringBuffer buf, TileLayer layer) { } private static String generateDemoUrl(String layerName, String gridSetId, MimeType type) { - return "%s".formatted( - layerName, gridSetId, type.getFormat(), type.getFileExtension()); + return "%s" + .formatted(layerName, gridSetId, type.getFormat(), type.getFileExtension()); } private static String generateHTML(TileLayer layer, String gridSetStr, String formatStr) @@ -277,7 +285,8 @@ private static String generateHTML(TileLayer layer, String gridSetStr, String fo buf.append(" ").append(escapeHtml4(gridSubset.getName())); buf.append(" ").append(escapeHtml4(formatStr)); buf.append("\n"); - buf.append(""" + buf.append( + """