-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PMD errors in core when run with Java 21
* `Thread.getId()` is deprecated. Since it's only used for reporting errors, use `Thread.getName()` instead * `new URL(String)` is deprecated. Use `new URI(String).toURL()` instead, throwing `MalformedURLException` to preserve the old behavior in methods that throw `IOException`. This is centralized in the new utility class/method `org.geowebcache.util.URLs.of(String url)` * `ExecutorService` implements `AutoCloseable` in Java 21, add `@SuppressWarnings("PMD.CloseResource")` in the test classes that use it * Add `@SuppressFBWarnings` for new rules
- Loading branch information
Showing
27 changed files
with
111 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
geowebcache/core/src/main/java/org/geowebcache/util/URLs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* | ||
* <p>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. | ||
* | ||
* <p>You should have received a copy of the GNU Lesser General Public License along with this | ||
* program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* @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. | ||
* | ||
* <p>Prefer this method to {@code new URL(String)}, which is <a | ||
* href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/net/URL.html#constructor-deprecation">deprecated | ||
* in Java 21</a>. | ||
* | ||
* <p>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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.