Skip to content

Commit 6ef09ed

Browse files
committed
catch the numberformatexception
1 parent efae445 commit 6ef09ed

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/AddressNormalizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
3333
// otherwise, we have a scheme but no host, so we assume the scheme is actually the host and the SSP is the port
3434
try {
3535
uri = new URI(scheme, null, uri.getScheme(), Integer.parseInt(uri.getSchemeSpecificPart()), null, null, null);
36-
} catch (URISyntaxException e) {
36+
} catch (URISyntaxException | NumberFormatException e) {
3737
throw new SDKException("error trying to create URL for host and port[" + urlString + "]", e);
3838
}
3939
}

sdk/src/test/java/io/opentdf/platform/sdk/AddressNormalizerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import static io.opentdf.platform.sdk.AddressNormalizer.normalizeAddress;
77
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
8+
import static org.junit.Assert.assertThrows;
89

910
class AddressNormalizerTest {
1011

@@ -26,4 +27,13 @@ void testAddressNormaliationWithInsecureHTTPClient() {
2627
assertThat(normalizeAddress("sftp://example.org", true)).isEqualTo("http://example.org:80");
2728
assertThat(normalizeAddress("keycloak.vm", true)).isEqualTo("http://keycloak.vm:80");
2829
}
30+
31+
@Test
32+
void testAddressNormalizationWithInvalidPort() {
33+
var thrown = assertThrows(SDKException.class, () -> normalizeAddress("example.org:notaport", true));
34+
assertThat(thrown.getMessage()).contains("example.org:notaport");
35+
36+
thrown = assertThrows(SDKException.class, () -> normalizeAddress("http://example.org:notaport", true));
37+
assertThat(thrown.getMessage()).contains("http://example.org:notaport");
38+
}
2939
}

0 commit comments

Comments
 (0)