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 4a5ac008d2..2aa9726e53 100644 --- a/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java +++ b/geowebcache/azureblob/src/main/java/org/geowebcache/azure/AzureClient.java @@ -40,7 +40,6 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.Proxy; -import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -48,6 +47,7 @@ import java.util.Properties; import javax.annotation.Nullable; import org.geowebcache.storage.StorageException; +import org.geowebcache.util.URLs; import org.springframework.http.HttpStatus; class AzureClient implements Closeable { @@ -86,7 +86,7 @@ public AzureClient(AzureBlobStoreData configuration) throws StorageException { PipelineOptions options = new PipelineOptions().withClient(client); ServiceURL serviceURL = new ServiceURL( - new URL(getServiceURL(configuration)), + URLs.of(getServiceURL(configuration)), StorageURL.createPipeline(creds, options)); String containerName = configuration.getContainer(); 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 e9c65be9cb..30513e3af0 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLConfiguration.java @@ -88,6 +88,7 @@ import org.geowebcache.storage.UnsuitableStorageException; import org.geowebcache.util.ApplicationContextProvider; import org.geowebcache.util.ExceptionUtils; +import org.geowebcache.util.URLs; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -266,10 +267,10 @@ public void setDefaultValues(TileLayer layer) { URL proxyUrl = null; try { if (getGwcConfig().getProxyUrl() != null) { - proxyUrl = new URL(getGwcConfig().getProxyUrl()); + proxyUrl = URLs.of(getGwcConfig().getProxyUrl()); log.fine("Using proxy " + proxyUrl.getHost() + ":" + proxyUrl.getPort()); } else if (wl.getProxyUrl() != null) { - proxyUrl = new URL(wl.getProxyUrl()); + proxyUrl = URLs.of(wl.getProxyUrl()); log.fine("Using proxy " + proxyUrl.getHost() + ":" + proxyUrl.getPort()); } } catch (MalformedURLException e) { 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 b2e465b7d1..f4b2e11378 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java +++ b/geowebcache/core/src/main/java/org/geowebcache/config/XMLOldGrid.java @@ -22,6 +22,7 @@ import org.geowebcache.grid.GridSubset; import org.geowebcache.grid.GridSubsetFactory; import org.geowebcache.grid.SRS; +import org.geowebcache.util.SuppressFBWarnings; /** * This class exists mainly to parse the old XML objects using XStream @@ -29,6 +30,11 @@ *

The problem is that it cannot use the GridSetBroker, so we end up with one GridSet per layer * anyway. */ +@SuppressFBWarnings({ + "NP_UNWRITTEN_FIELD", + "NP_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", + "UWF_NULL_FIELD" +}) // field assignment done by XStream public class XMLOldGrid implements Serializable { private static final long serialVersionUID = 1413422643636728997L; 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 4e866e324a..c72cdecef9 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 @@ -34,6 +34,7 @@ import org.geowebcache.layer.wms.WMSLayer; import org.geowebcache.mime.ImageMime; import org.geowebcache.util.ServletUtils; +import org.geowebcache.util.URLs; public class WMSRasterFilter extends RasterFilter { @@ -110,7 +111,7 @@ protected BufferedImage loadMatrix(TileLayer tlayer, String gridSetId, int z) + ") , " + urlStr); - URL wmsUrl = new URL(urlStr); + URL wmsUrl = URLs.of(urlStr); if (backendTimeout == null) { backendTimeout = 120; diff --git a/geowebcache/core/src/main/java/org/geowebcache/layer/TileLayerDispatcher.java b/geowebcache/core/src/main/java/org/geowebcache/layer/TileLayerDispatcher.java index 93b7729900..09a545754a 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/layer/TileLayerDispatcher.java +++ b/geowebcache/core/src/main/java/org/geowebcache/layer/TileLayerDispatcher.java @@ -113,7 +113,7 @@ public TileLayer getTileLayer(final String layerName) throws GeoWebCacheExceptio } throw new GeoWebCacheException( "Thread " - + Thread.currentThread().getId() + + Thread.currentThread().getName() + " Unknown layer " + layerName + ". Check the logfiles," diff --git a/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java b/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java index 58fa3b66c4..782c9bad21 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java +++ b/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSHttpHelper.java @@ -46,6 +46,7 @@ import org.geowebcache.util.GWCVars; import org.geowebcache.util.HttpClientBuilder; import org.geowebcache.util.ServletUtils; +import org.geowebcache.util.URLs; import org.springframework.util.Assert; /** This class is a wrapper for HTTP interaction with WMS backend */ @@ -115,7 +116,7 @@ protected void makeRequest( String requestUrl = layer.nextWmsURL(); try { - wmsBackendUrl = new URL(requestUrl); + wmsBackendUrl = URLs.of(requestUrl); } catch (MalformedURLException maue) { throw new GeoWebCacheException( "Malformed URL: " + requestUrl + " " + maue.getMessage()); diff --git a/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSLayer.java b/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSLayer.java index c5acd475e4..c5532db7ce 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSLayer.java +++ b/geowebcache/core/src/main/java/org/geowebcache/layer/wms/WMSLayer.java @@ -54,6 +54,7 @@ import org.geowebcache.mime.MimeType; import org.geowebcache.mime.XMLMime; import org.geowebcache.util.GWCVars; +import org.geowebcache.util.URLs; /** A tile layer backed by a WMS server */ public class WMSLayer extends AbstractTileLayer implements ProxyLayer { @@ -803,9 +804,9 @@ public void proxyRequest(ConveyorTile tile) throws GeoWebCacheException { try { URL url; if (serverStr.contains("?")) { - url = new URL(serverStr + "&" + queryStr); + url = URLs.of(serverStr + "&" + queryStr); } else { - url = new URL(serverStr + queryStr); + url = URLs.of(serverStr + queryStr); } WMSSourceHelper helper = getSourceHelper(); diff --git a/geowebcache/core/src/main/java/org/geowebcache/locks/NIOLockProvider.java b/geowebcache/core/src/main/java/org/geowebcache/locks/NIOLockProvider.java index 500945e1b3..cdedf4aa7f 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/locks/NIOLockProvider.java +++ b/geowebcache/core/src/main/java/org/geowebcache/locks/NIOLockProvider.java @@ -115,7 +115,7 @@ public LockProvider.Lock getLock(final String lockKey) throws GeoWebCacheExcepti "Lock " + lockKey + " acquired by thread " - + Thread.currentThread().getId() + + Thread.currentThread().getName() + " on file " + file); } @@ -151,7 +151,7 @@ public void release() throws GeoWebCacheException { + " for releasing lock is unkonwn, it means " + "this lock was never acquired, or was released twice. " + "Current thread is: " - + Thread.currentThread().getId() + + Thread.currentThread().getName() + ". " + "Are you running two GWC instances in the same JVM using NIO locks? " + "This case is not supported and will generate exactly this error message"); @@ -170,7 +170,7 @@ public void release() throws GeoWebCacheException { + " on file " + lockFile + " released by thread " - + Thread.currentThread().getId()); + + Thread.currentThread().getName()); } } catch (IOException e) { throw new GeoWebCacheException( diff --git a/geowebcache/core/src/main/java/org/geowebcache/proxy/ProxyDispatcher.java b/geowebcache/core/src/main/java/org/geowebcache/proxy/ProxyDispatcher.java index 1db4fe9527..000d385e1a 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/proxy/ProxyDispatcher.java +++ b/geowebcache/core/src/main/java/org/geowebcache/proxy/ProxyDispatcher.java @@ -22,6 +22,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.geotools.util.logging.Logging; +import org.geowebcache.util.URLs; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.AbstractController; @@ -62,7 +63,7 @@ protected ModelAndView handleRequestInternal( } String decodedUrl = URLDecoder.decode(urlStr, charEnc); - URL url = new URL(decodedUrl); + URL url = URLs.of(decodedUrl); HttpURLConnection wmsBackendCon = (HttpURLConnection) url.openConnection(); if (wmsBackendCon.getContentEncoding() != null) { 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 1ccbe669cf..bc6d841ae2 100644 --- a/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java +++ b/geowebcache/core/src/main/java/org/geowebcache/storage/BlobStoreAggregator.java @@ -103,7 +103,7 @@ public BlobStoreInfo getBlobStore(final String blobStoreName) throws GeoWebCache () -> new GeoWebCacheException( "Thread " - + Thread.currentThread().getId() + + Thread.currentThread().getName() + " Unknown blob store " + blobStoreName + ". Check the logfiles," diff --git a/geowebcache/core/src/main/java/org/geowebcache/util/URLs.java b/geowebcache/core/src/main/java/org/geowebcache/util/URLs.java new file mode 100644 index 0000000000..ba63849488 --- /dev/null +++ b/geowebcache/core/src/main/java/org/geowebcache/util/URLs.java @@ -0,0 +1,54 @@ +/** + * This program is free software: you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + *

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + *

You should have received a copy of the GNU Lesser General Public License along with this + * program. If not, see . + * + * @author Gabriel Roldan, Camptocamp, Copyright 2023 + */ +package org.geowebcache.util; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +/** Utilities for manipulating and converting to and from {@link URL}s. */ +public class URLs { + + private URLs() { + // private constructor signaling this is a pure-utility class + } + + /** + * Creates a {@code URL} object from the {@code String} representation. + * + *

Prefer this method to {@code new URL(String)}, which is deprecated + * in Java 21. + * + *

Note a {@link URISyntaxException} will be rethrown as {@link MalformedURLException} to + * preserve the behavior of code that used to call {@code new URL(String)} and expected either a + * {@code MalformedURLException} or its super type {@code java.io.IOException}. + * + * @param url a URL string to build a {@link URL} from + * @return the URL built from the argument + * @throws MalformedURLException if {code}url{code} is not a valid {@link URI} nor a valid + * {@link URL} as per {@link URI#toURL()} + */ + public static URL of(String url) throws MalformedURLException { + try { + return new URI(url).toURL(); + } catch (URISyntaxException orig) { + MalformedURLException e = new MalformedURLException(orig.getMessage()); + e.initCause(orig); + throw e; + } + } +} diff --git a/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java b/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java index b4e9397e12..0050490bf5 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/blobstore/file/FileBlobStoreComformanceTest.java @@ -50,6 +50,7 @@ public void createTestUnit() throws Exception { private void putLayerMetadataConcurrently( final int srcStoreKey, final FileBlobStore srcStore, int numberOfThreads) throws InterruptedException { + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService service = Executors.newFixedThreadPool(numberOfThreads); CountDownLatch latch = new CountDownLatch(numberOfThreads); for (int i = 0; i < numberOfThreads; i++) { @@ -75,6 +76,7 @@ private void putLayerMetadataConcurrently( private void executeStoresConcurrently(int numberOfStores, int numberOfThreads) throws InterruptedException { + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService service = Executors.newFixedThreadPool(numberOfStores); CountDownLatch latch = new CountDownLatch(numberOfStores); for (int i = 0; i < numberOfStores; i++) { @@ -106,6 +108,7 @@ public void testMetadataWithPointInKey() throws Exception { public void testConcurrentMetadataWithPointInKey() throws InterruptedException { assertThat(store.getLayerMetadata("testLayer", "test.Key"), nullValue()); int numberOfThreads = 2; + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService service = Executors.newFixedThreadPool(numberOfThreads); CountDownLatch latch = new CountDownLatch(numberOfThreads); for (int i = 0; i < numberOfThreads; i++) { diff --git a/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java b/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java index 9e967a28f3..2b6ef36c9e 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/ConfigurationTest.java @@ -345,6 +345,7 @@ public void testConcurrentAdds() throws Exception { defaultCount + 10, getInfoNames(config).size()); // get a thread pool + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService pool = Executors.newFixedThreadPool( 16, (Runnable r) -> new Thread(r, "Info Concurrency Test for ADD")); @@ -389,6 +390,7 @@ public void testConcurrentDeletes() throws Exception { defaultCount + 100, getInfoNames(config).size()); // get a thread pool + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService pool = Executors.newFixedThreadPool( 16, (Runnable r) -> new Thread(r, "Info Concurrency Test for DELETE")); @@ -431,6 +433,7 @@ public void testConcurrentModifies() throws Exception { defaultCount + 100, getInfoNames(config).size()); // get a thread pool + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService pool = Executors.newFixedThreadPool( 16, (Runnable r) -> new Thread(r, "Info Concurrency Test for MODIFY")); 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 6b5a2e1457..684a2b1704 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/config/DefaultingConfigurationTest.java @@ -27,6 +27,7 @@ import org.geowebcache.layer.TileLayer; import org.geowebcache.layer.wms.WMSHttpHelper; import org.geowebcache.layer.wms.WMSLayer; +import org.geowebcache.util.URLs; import org.junit.Test; public class DefaultingConfigurationTest { @@ -111,9 +112,9 @@ public void setDefaultValues(TileLayer layer) { URL proxyUrl = null; try { if (getGwcConfig().getProxyUrl() != null) { - proxyUrl = new URL(getGwcConfig().getProxyUrl()); + proxyUrl = URLs.of(getGwcConfig().getProxyUrl()); } else if (wl.getProxyUrl() != null) { - proxyUrl = new URL(wl.getProxyUrl()); + proxyUrl = URLs.of(wl.getProxyUrl()); } } catch (MalformedURLException e) { } diff --git a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java index dbb4f32a2d..353bbdaea9 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/layer/wms/WMSLayerTest.java @@ -601,6 +601,7 @@ private List getTiles( long[] gridLoc = trIter.nextMetaGridLocation(new long[3]); // six concurrent requests max + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService requests = Executors.newFixedThreadPool(6); ExecutorCompletionService completer = new ExecutorCompletionService<>(requests); diff --git a/geowebcache/core/src/test/java/org/geowebcache/storage/TileRangeIteratorTest.java b/geowebcache/core/src/test/java/org/geowebcache/storage/TileRangeIteratorTest.java index 0a096a751b..2108b390e5 100644 --- a/geowebcache/core/src/test/java/org/geowebcache/storage/TileRangeIteratorTest.java +++ b/geowebcache/core/src/test/java/org/geowebcache/storage/TileRangeIteratorTest.java @@ -215,6 +215,7 @@ private long traverseTileRangeIter( final int[] metaTilingFactors) throws Exception { + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 final ExecutorService executorService = Executors.newFixedThreadPool(nThreads); final TileRange tileRange; diff --git a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PagePyramid.java b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PagePyramid.java index b558728661..579db35cd6 100644 --- a/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PagePyramid.java +++ b/geowebcache/diskquota/core/src/main/java/org/geowebcache/diskquota/storage/PagePyramid.java @@ -16,7 +16,6 @@ import java.math.BigInteger; import java.text.NumberFormat; -import java.util.Locale; import java.util.Map; import java.util.TreeMap; import org.geowebcache.grid.GridSubset; @@ -84,7 +83,7 @@ public PageLevelInfo( @Override public String toString() { - NumberFormat nf = NumberFormat.getInstance(new Locale("es")); + NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(true); return "Pages: " diff --git a/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/storage/PagePyramidTest.java b/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/storage/PagePyramidTest.java index 1aa008da3e..cd0d1d0502 100644 --- a/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/storage/PagePyramidTest.java +++ b/geowebcache/diskquota/core/src/test/java/org/geowebcache/diskquota/storage/PagePyramidTest.java @@ -22,7 +22,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.logging.Logger; import org.geotools.util.logging.Logging; import org.geowebcache.config.DefaultGridsets; @@ -76,7 +75,7 @@ public void testCalculatePageInfo() { } private void printPyramid(int zoomStart, int zoomStop, PagePyramid pp) { - NumberFormat nf = NumberFormat.getInstance(new Locale("es")); + NumberFormat nf = NumberFormat.getInstance(); nf.setGroupingUsed(true); long totalPages = 0; 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 1c9b5be259..ac3deb278c 100644 --- a/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java +++ b/geowebcache/georss/src/main/java/org/geowebcache/georss/GeoRSSPollTask.java @@ -37,6 +37,7 @@ import org.geowebcache.storage.DiscontinuousTileRange; import org.geowebcache.storage.RasterMask; import org.geowebcache.storage.StorageBroker; +import org.geowebcache.util.URLs; /** * A task to run a GeoRSS feed poll and launch the seeding process @@ -128,7 +129,7 @@ private void runPollAndLaunchSeed() throws IOException { final String previousUpdatedEntry = storageBroker.getLayerMetadata(layerName, LAST_UPDATED); final String gridSetId = pollDef.getGridSetId(); - final URL feedUrl = new URL(templateFeedUrl(pollDef.getFeedUrl(), previousUpdatedEntry)); + URL feedUrl = URLs.of(templateFeedUrl(pollDef.getFeedUrl(), previousUpdatedEntry)); final String httpUsername = pollDef.getHttpUsername(); final String httpPassword = pollDef.getHttpUsername(); 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 9e3b0fb4b7..d472f3d074 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqliteConnectionManagerTest.java @@ -161,6 +161,7 @@ private void genericMultiThreadsTest( int threadsNumber, int workersNumber, long poolSize, File... files) throws Exception { SqliteConnectionManager connectionManager = new SqliteConnectionManager(poolSize, 10); connectionManagersToClean.add(connectionManager); + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService executor = Executors.newFixedThreadPool(threadsNumber); Random random = new Random(); List>> results = new ArrayList<>(); 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 da6fe3ac53..4ef0f39f3c 100644 --- a/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java +++ b/geowebcache/sqlite/src/test/java/org/geowebcache/sqlite/SqlitlePerf.java @@ -80,6 +80,7 @@ private static void rawSqlitle(File rootDirectory, File seedFile, long[][] tiles } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService executor = Executors.newFixedThreadPool(WORKERS); long startTime = System.currentTimeMillis(); try (Connection connection = @@ -124,6 +125,7 @@ private static void pooledSqlitle(File rootDirectory, File seedFile, long[][] ti } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService executor = Executors.newFixedThreadPool(WORKERS); SqliteConnectionManager connectionManager = new SqliteConnectionManager(10, 2000); long startTime = System.currentTimeMillis(); @@ -179,6 +181,7 @@ private static void mbtilesStore(File rootDirectory, File seedFile, long[][] til } FileUtils.copyFile(seedFile, databaseFile); // submitting the select tasks + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService executor = Executors.newFixedThreadPool(WORKERS); long startTime = System.currentTimeMillis(); // mbtiles store configuration @@ -240,6 +243,7 @@ private static void fileStore(File seedDirectory, long[][] tiles) throws Excepti LOGGER.info(String.format("Start reading from directory'%s'.", seedDirectory)); } // submitting the read tasks + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ExecutorService executor = Executors.newFixedThreadPool(WORKERS); long startTime = System.currentTimeMillis(); // instantiate the file blobstore diff --git a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java index 3a4b82c14b..69bd951611 100644 --- a/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java +++ b/geowebcache/swiftblob/src/test/java/org/geowebcache/swift/SwiftBlobStoreTest.java @@ -696,6 +696,7 @@ public void deleteByParametersId() { @Ignore // unreliable test timing public void deleteWhenUploadExists() throws Exception { BlockingQueue taskQueue = spy(new LinkedBlockingQueue<>(1000)); + @SuppressWarnings("PMD.CloseResource") // implements AutoCloseable in Java 21 ThreadPoolExecutor executor = spy( new ThreadPoolExecutor( diff --git a/geowebcache/wms/src/main/java/org/geowebcache/config/wms/GetCapabilitiesConfiguration.java b/geowebcache/wms/src/main/java/org/geowebcache/config/wms/GetCapabilitiesConfiguration.java index 5da8b4ab5b..e9b97fbe01 100644 --- a/geowebcache/wms/src/main/java/org/geowebcache/config/wms/GetCapabilitiesConfiguration.java +++ b/geowebcache/wms/src/main/java/org/geowebcache/config/wms/GetCapabilitiesConfiguration.java @@ -16,7 +16,6 @@ import com.google.common.collect.Sets; import java.io.IOException; -import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -70,6 +69,7 @@ import org.geowebcache.layer.meta.MetadataURL; import org.geowebcache.layer.wms.WMSHttpHelper; import org.geowebcache.layer.wms.WMSLayer; +import org.geowebcache.util.URLs; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -521,7 +521,7 @@ private WMSLayer getLayer( WebMapServer getWMS() throws IOException, ServiceException { Map hints = new HashMap<>(); hints.put(XMLHandlerHints.ENTITY_RESOLVER, PreventLocalEntityResolver.INSTANCE); - return new WebMapServer(new URL(url), HTTPClientFinder.createClient(), hints); + return new WebMapServer(URLs.of(url), HTTPClientFinder.createClient(), hints); } private String parseVersion(String url) { diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java index 7dd0e02679..deb6615c1d 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesConfigurationTest.java @@ -29,7 +29,6 @@ import static org.junit.Assert.assertThat; import com.google.common.collect.Sets; -import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -49,6 +48,7 @@ import org.geowebcache.grid.GridSetBroker; import org.geowebcache.layer.TileLayer; import org.geowebcache.layer.wms.WMSLayer; +import org.geowebcache.util.URLs; import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Test; @@ -78,7 +78,7 @@ public void setUp() throws Exception { expect(req.getGetCapabilities()).andStubReturn(gcOpType); expect(gcOpType.getGet()) .andStubReturn( - new URL( + URLs.of( "http://test/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities")); expect(cap.getVersion()).andStubReturn("1.1.1"); } @@ -215,7 +215,7 @@ WebMapServer getWMS() { expect(req.getGetCapabilities()).andStubReturn(gcOpType); expect(gcOpType.getGet()) .andStubReturn( - new URL( + URLs.of( "http://test/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities")); expect(cap.getVersion()).andStubReturn("1.1.1"); 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 0e61c35f7c..68d322f10a 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 @@ -22,7 +22,6 @@ import static org.junit.Assert.assertThat; import com.google.common.base.Objects; -import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -41,6 +40,7 @@ import org.geowebcache.grid.GridSetBroker; import org.geowebcache.grid.GridSubset; import org.geowebcache.layer.TileLayer; +import org.geowebcache.util.URLs; import org.hamcrest.CustomMatcher; import org.hamcrest.Matcher; import org.junit.Assume; @@ -97,7 +97,7 @@ protected GridSetConfiguration getConfig() throws Exception { expect(req.getGetCapabilities()).andStubReturn(gcOpType); expect(gcOpType.getGet()) .andStubReturn( - new URL( + URLs.of( "http://test/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities")); expect(cap.getVersion()).andStubReturn("1.1.1"); EasyMock.replay(server, cap, req, gcOpType, globalConfig); diff --git a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java index 7c456bf476..b35af388ba 100644 --- a/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java +++ b/geowebcache/wms/src/test/java/org/geowebcache/config/wms/GetCapabilitiesLayerConfigurationConformanceTest.java @@ -19,7 +19,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; -import java.net.URL; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -38,6 +37,7 @@ import org.geowebcache.grid.GridSubsetFactory; import org.geowebcache.layer.TileLayer; import org.geowebcache.layer.wms.WMSLayer; +import org.geowebcache.util.URLs; import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.junit.Assume; @@ -120,7 +120,7 @@ protected TileLayerConfiguration getConfig() throws Exception { expect(req.getGetCapabilities()).andStubReturn(gcOpType); expect(gcOpType.getGet()) .andStubReturn( - new URL( + URLs.of( "http://test/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities")); expect(cap.getVersion()).andStubReturn("1.1.1"); EasyMock.replay(server, cap, req, gcOpType, globalConfig); diff --git a/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java b/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java index a3def36831..a97baa10ba 100644 --- a/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java +++ b/geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java @@ -85,6 +85,7 @@ import org.geowebcache.stats.RuntimeStats; import org.geowebcache.storage.StorageBroker; import org.geowebcache.util.NullURLMangler; +import org.geowebcache.util.URLs; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -358,7 +359,7 @@ public void testGetCap() throws Exception { // add some layer metadata MetadataURL metadataURL = new MetadataURL( - "some-type", "some-format", new URL("http://localhost:8080/some-url")); + "some-type", "some-format", URLs.of("http://localhost:8080/some-url")); when(tileLayer.getMetadataURLs()).thenReturn(Collections.singletonList(metadataURL)); }