Skip to content

Commit f18c562

Browse files
committed
fix: handle maformed resources [URL, URI]
1 parent 32d090e commit f18c562

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/main/java/org/eclipse/yasson/internal/deserializer/types/UriDeserializer.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -14,9 +14,12 @@
1414

1515
import java.lang.reflect.Type;
1616
import java.net.URI;
17+
import java.net.URISyntaxException;
1718

1819
import org.eclipse.yasson.internal.DeserializationContextImpl;
1920

21+
import jakarta.json.bind.JsonbException;
22+
2023
/**
2124
* Deserializer of the {@link URI} type.
2225
*/
@@ -28,6 +31,11 @@ class UriDeserializer extends TypeDeserializer {
2831

2932
@Override
3033
Object deserializeStringValue(String value, DeserializationContextImpl context, Type rType) {
31-
return URI.create(value);
34+
try {
35+
return new URI(value);
36+
} catch (URISyntaxException e) {
37+
// Exception will be caught and wrapped
38+
throw new JsonbException("java.net.URI could not parse value " + value, e);
39+
}
3240
}
3341
}

src/main/java/org/eclipse/yasson/internal/deserializer/types/UrlDeserializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -12,6 +12,8 @@
1212

1313
package org.eclipse.yasson.internal.deserializer.types;
1414

15+
import jakarta.json.bind.JsonbException;
16+
1517
import java.lang.reflect.Type;
1618
import java.net.MalformedURLException;
1719
import java.net.URL;
@@ -29,12 +31,10 @@ class UrlDeserializer extends TypeDeserializer {
2931

3032
@Override
3133
Object deserializeStringValue(String value, DeserializationContextImpl context, Type rType) {
32-
URL url = null;
3334
try {
34-
url = new URL(value);
35+
return new URL(value);
3536
} catch (MalformedURLException e) {
36-
e.printStackTrace();
37+
throw new JsonbException("java.net.URL could not parse value " + value, e);
3738
}
38-
return url;
3939
}
4040
}

0 commit comments

Comments
 (0)