Skip to content

Commit b5fe3c3

Browse files
committed
Refine YAML type restriction error
Closes spring-projectsgh-21596
1 parent 9503129 commit b5fe3c3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/json/YamlJsonParser.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.yaml.snakeyaml.Yaml;
2727
import org.yaml.snakeyaml.constructor.Constructor;
2828

29+
import org.springframework.util.Assert;
30+
2931
/**
3032
* Thin wrapper to adapt Snake {@link Yaml} to {@link JsonParser}.
3133
*
@@ -63,7 +65,9 @@ private static class TypeLimitedConstructor extends Constructor {
6365

6466
@Override
6567
protected Class<?> getClassForName(String name) throws ClassNotFoundException {
66-
return (SUPPORTED_TYPES.contains(name)) ? super.getClassForName(name) : null;
68+
Assert.state(SUPPORTED_TYPES.contains(name),
69+
() -> "Unsupported '" + name + "' type encountered in YAML document");
70+
return super.getClassForName(name);
6771
}
6872

6973
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/json/YamlJsonParserTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ protected JsonParser getParser() {
3636
@Test
3737
public void customTypesAreNotLoaded() throws Exception {
3838
assertThatExceptionOfType(ConstructorException.class)
39-
.isThrownBy(() -> getParser().parseMap("{value: !!java.net.URL [\"http://localhost:9000/\"]}"));
39+
.isThrownBy(() -> getParser().parseMap("{value: !!java.net.URL [\"http://localhost:9000/\"]}"))
40+
.withCauseInstanceOf(IllegalStateException.class);
4041
}
4142

4243
}

0 commit comments

Comments
 (0)