Skip to content

Commit 1fa6694

Browse files
authored
[4.x] Adopt SnakeYAML 2.0; add integration tests for reactive and Nima (#6535)
1 parent 6c801eb commit 1fa6694

File tree

36 files changed

+1663
-40
lines changed

36 files changed

+1663
-40
lines changed

config/yaml-mp/src/main/java/io/helidon/config/yaml/mp/YamlMpConfigSource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import io.helidon.config.MutabilitySupport;
4040

4141
import org.eclipse.microprofile.config.spi.ConfigSource;
42+
import org.yaml.snakeyaml.LoaderOptions;
4243
import org.yaml.snakeyaml.Yaml;
4344
import org.yaml.snakeyaml.constructor.SafeConstructor;
4445

@@ -380,7 +381,7 @@ public String getName() {
380381
static Map toMap(Reader reader) {
381382
// the default of Snake YAML is a Map, safe constructor makes sure we never deserialize into anything
382383
// harmful
383-
Yaml yaml = new Yaml(new SafeConstructor());
384+
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
384385
return (Map) yaml.loadAs(reader, Object.class);
385386
}
386387
}

config/yaml/src/main/java/io/helidon/config/yaml/YamlConfigParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@
3232
import io.helidon.config.spi.ConfigParser;
3333
import io.helidon.config.spi.ConfigParserException;
3434

35+
import org.yaml.snakeyaml.LoaderOptions;
3536
import org.yaml.snakeyaml.Yaml;
3637
import org.yaml.snakeyaml.constructor.SafeConstructor;
3738

@@ -113,7 +114,7 @@ public ObjectNode parse(Content content) throws ConfigParserException {
113114
static Map toMap(Reader reader) {
114115
// the default of Snake YAML is a Map, safe constructor makes sure we never deserialize into anything
115116
// harmful
116-
Yaml yaml = new Yaml(new SafeConstructor());
117+
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
117118
return (Map) yaml.loadAs(reader, Object.class);
118119
}
119120

dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
<version.lib.prometheus>0.9.0</version.lib.prometheus>
144144
<version.lib.slf4j>2.0.0</version.lib.slf4j>
145145
<version.lib.smallrye-openapi>2.1.16</version.lib.smallrye-openapi>
146-
<version.lib.snakeyaml>1.32</version.lib.snakeyaml>
146+
<version.lib.snakeyaml>2.0</version.lib.snakeyaml>
147147
<version.lib.typesafe-config>1.4.2</version.lib.typesafe-config>
148148
<version.lib.tyrus>2.0.4</version.lib.tyrus>
149149
<version.lib.weld-api>5.0.SP3</version.lib.weld-api>

examples/todo-app/backend/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<version.datastax.driver.core>4.9.0</version.datastax.driver.core>
4343
<version.datastax.driver.query.builder>4.9.0</version.datastax.driver.query.builder>
4444
<version.codahale.metrics.core>3.0.2</version.codahale.metrics.core>
45+
<version.lib.snakeyaml.override>1.32</version.lib.snakeyaml.override>
4546
</properties>
4647

4748
<dependencyManagement>
@@ -57,6 +58,11 @@
5758
</exclusion>
5859
</exclusions>
5960
</dependency>
61+
<dependency>
62+
<groupId>org.yaml</groupId>
63+
<artifactId>snakeyaml</artifactId>
64+
<version>${version.lib.snakeyaml.override}</version>
65+
</dependency>
6066
</dependencies>
6167
</dependencyManagement>
6268

microprofile/tests/tck/tck-openapi/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@
3030
<artifactId>tck-openapi</artifactId>
3131
<name>Helidon Microprofile Tests TCK OpenAPI</name>
3232

33+
<properties>
34+
<selectedSnakeYamlVersion>1.32</selectedSnakeYamlVersion>
35+
</properties>
36+
37+
<!-- The TCK uses Jackson which in turn uses SnakeYAML APIs that have disappeared in 2.0. So, for running the TCK
38+
use the earlier SnakeYAML release (until an updated Jackson release becomes available). -->
39+
<dependencyManagement>
40+
<dependencies>
41+
<dependency>
42+
<groupId>org.yaml</groupId>
43+
<artifactId>snakeyaml</artifactId>
44+
<version>${selectedSnakeYamlVersion}</version>
45+
</dependency>
46+
</dependencies>
47+
</dependencyManagement>
48+
3349
<dependencies>
3450
<dependency>
3551
<groupId>io.helidon.microprofile.tests</groupId>

nima/openapi/src/main/java/io/helidon/nima/openapi/OpenApiService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,9 @@ private OpenApiStaticFile getExplicitStaticFile() {
739739
+ " is not one of recognized types: "
740740
+ OpenAPIMediaType.recognizedFileTypes()));
741741

742-
try (InputStream is = new BufferedInputStream(Files.newInputStream(path))) {
742+
// DO NOT use try-with-close; the stream needs to remain open because it is not consumed until later.
743+
try {
744+
InputStream is = new BufferedInputStream(Files.newInputStream(path));
743745
LOGGER.log(Level.DEBUG,
744746
() -> String.format(
745747
OPENAPI_EXPLICIT_STATIC_FILE_LOG_MESSAGE_FORMAT,

openapi/src/main/java/io/helidon/openapi/CustomConstructor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.eclipse.microprofile.openapi.models.responses.APIResponse;
3030
import org.eclipse.microprofile.openapi.models.responses.APIResponses;
3131
import org.eclipse.microprofile.openapi.models.security.SecurityRequirement;
32+
import org.yaml.snakeyaml.LoaderOptions;
3233
import org.yaml.snakeyaml.TypeDescription;
3334
import org.yaml.snakeyaml.constructor.Constructor;
3435
import org.yaml.snakeyaml.error.Mark;
@@ -148,7 +149,7 @@ record ChildMapType<P, C>(Class<P> parentType,
148149
Function<Class<?>, ExpandedTypeDescription.MapLikeTypeDescription<P, C>> typeDescriptionFactory) { }
149150

150151
/**
151-
* Type information about a map-resembling interface in which a child can have 0, 1, or more values i.e., the child is
152+
* Type information about a map-resembling interface in which a child can have 0, 1, or more values (i.e., the child is
152153
* a list).
153154
*
154155
* @param <P> parent type
@@ -165,7 +166,7 @@ record ChildMapListType<P, C>(
165166
private static final System.Logger LOGGER = System.getLogger(CustomConstructor.class.getName());
166167

167168
CustomConstructor(TypeDescription td) {
168-
super(td);
169+
super(td, new LoaderOptions());
169170
yamlClassConstructors.put(NodeId.mapping, new ConstructMapping());
170171
}
171172

openapi/src/main/java/io/helidon/openapi/ImplTypeDescription.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
2+
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,46 +61,18 @@ public Tag getTag() {
6161
return delegate.getTag();
6262
}
6363

64-
@Override
65-
public void setTag(Tag tag) {
66-
delegate.setTag(tag);
67-
}
68-
69-
@Override
70-
public void setTag(String tag) {
71-
delegate.setTag(tag);
72-
}
73-
7464
@Override
7565
@Deprecated
7666
public void putListPropertyType(String property, Class<?> type) {
7767
delegate.putListPropertyType(property, type);
7868
}
7969

80-
@Override
81-
@Deprecated
82-
public Class<? extends Object> getListPropertyType(String property) {
83-
return delegate.getListPropertyType(property);
84-
}
85-
8670
@Override
8771
@Deprecated
8872
public void putMapPropertyType(String property, Class<?> key, Class<?> value) {
8973
delegate.putMapPropertyType(property, key, value);
9074
}
9175

92-
@Override
93-
@Deprecated
94-
public Class<? extends Object> getMapKeyType(String property) {
95-
return delegate.getMapKeyType(property);
96-
}
97-
98-
@Override
99-
@Deprecated
100-
public Class<? extends Object> getMapValueType(String property) {
101-
return delegate.getMapValueType(property);
102-
}
103-
10476
@Override
10577
public void addPropertyParameters(String pName, Class<?>... classes) {
10678
delegate.addPropertyParameters(pName, classes);

openapi/src/main/java/io/helidon/openapi/ParserHelper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,13 +32,24 @@
3232
* Wraps generated parser and uses {@link io.helidon.openapi.ExpandedTypeDescription} as its type.
3333
*/
3434
public class ParserHelper {
35+
36+
// Temporary to suppress SnakeYAML warnings.
37+
// As a static we keep a reference to the logger, thereby making sure any changes we make are persistent. (JUL holds
38+
// only weak references to loggers internally.)
39+
private static final java.util.logging.Logger SNAKE_YAML_INTROSPECTOR_LOGGER =
40+
java.util.logging.Logger.getLogger(org.yaml.snakeyaml.introspector.PropertySubstitute.class.getPackage().getName());
41+
3542
/**
3643
* The SnakeYAMLParserHelper is generated by a maven plug-in.
3744
*/
3845
private final SnakeYAMLParserHelper<ExpandedTypeDescription> generatedHelper;
3946

4047
private ParserHelper(SnakeYAMLParserHelper<ExpandedTypeDescription> generatedHelper) {
4148
this.generatedHelper = generatedHelper;
49+
boolean warningsEnabled = Boolean.getBoolean("openapi.parsing.warnings.enabled");
50+
if (SNAKE_YAML_INTROSPECTOR_LOGGER.isLoggable(java.util.logging.Level.WARNING) && !warningsEnabled) {
51+
SNAKE_YAML_INTROSPECTOR_LOGGER.setLevel(java.util.logging.Level.SEVERE);
52+
}
4253
}
4354

4455
/**

openapi/src/main/java/io/helidon/openapi/Serializer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,15 @@ static class CustomRepresenter extends Representer {
114114

115115
private static final String EXTENSIONS = "extensions";
116116

117-
private final DumperOptions dumperOptions;
118117
private final DumperOptions.ScalarStyle stringStyle;
119118

120119
private final Map<Class<?>, ExpandedTypeDescription> implsToTypes;
121120

122121
CustomRepresenter(Map<Class<?>, ExpandedTypeDescription> types,
123122
Map<Class<?>, ExpandedTypeDescription> implsToTypes, DumperOptions dumperOptions,
124123
DumperOptions.ScalarStyle stringStyle) {
124+
super(dumperOptions);
125125
this.implsToTypes = implsToTypes;
126-
this.dumperOptions = dumperOptions;
127126
this.stringStyle = stringStyle;
128127
types.values().stream()
129128
.map(ImplTypeDescription::new)

0 commit comments

Comments
 (0)