Skip to content

Commit dad3502

Browse files
committed
replace deprecated java.net.URL usage with java.net.URI (#94)
Deprecated in Java 20. Migrate URL parsing to backward compatible URI.
1 parent 0127cf3 commit dad3502

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Support Vault transit API (#89)
88
* Support PEM certificate string from `VAULT_CACERT` environment variable (#93)
99

10+
### Improvements
11+
* Replace deprecated `java.net.URL` usage with `java.net.URI` (#94)
12+
1013
### Dependencies
1114
* Updated Jackson to 2.18.3 (#90)
1215

src/main/java/de/stklcode/jvault/connector/HTTPVaultConnectorBuilder.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222

2323
import java.io.ByteArrayInputStream;
2424
import java.io.IOException;
25-
import java.net.MalformedURLException;
2625
import java.net.URI;
2726
import java.net.URISyntaxException;
28-
import java.net.URL;
2927
import java.nio.charset.StandardCharsets;
3028
import java.nio.file.Files;
3129
import java.nio.file.Path;
@@ -305,11 +303,11 @@ public HTTPVaultConnectorBuilder fromEnv() throws VaultConnectorException {
305303
/* Parse URL from environment variable */
306304
if (System.getenv(ENV_VAULT_ADDR) != null && !System.getenv(ENV_VAULT_ADDR).isBlank()) {
307305
try {
308-
var url = new URL(System.getenv(ENV_VAULT_ADDR));
309-
this.host = url.getHost();
310-
this.port = url.getPort();
311-
this.tls = url.getProtocol().equals("https");
312-
} catch (MalformedURLException e) {
306+
var uri = new URI(System.getenv(ENV_VAULT_ADDR));
307+
this.host = uri.getHost();
308+
this.port = uri.getPort();
309+
this.tls = uri.getScheme().equalsIgnoreCase("https");
310+
} catch (URISyntaxException e) {
313311
throw new ConnectionException("URL provided in environment variable malformed", e);
314312
}
315313
}

0 commit comments

Comments
 (0)