-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent behavior for default configuration value between Set and Map #28205
Comments
You can also have a look for a more in-depth discussion: microprofile/microprofile-config#446.
A change like this will be a breaking change, and while I'm always +1 for consistency, we need to be careful here. @dmlloyd any thoughts? |
Thanks for the explanation, that really helps to understand the background. So if Set/List/Array can't be changed easily, and |
I'll have a look. |
I think we hit something similar to what is described here, but in Quarkus 3.1.1 with kotlin. If we use The included example should demonstrates this behaviour, @ConfigMapping(prefix = "nested")
interface NestedConfig {
@WithDefault("")
fun list(): List<Nested>
interface Nested {
fun ok(): Map<String, String>
fun okAgain(): List<ComplexType>
fun notOk(): List<String> // Comment out/remove this line/add properties, and app starts like normal
interface ComplexType {
fun name(): String
}
}
} This "incosistent" handling doesn't exactly make sense to me. I would also expect this to work: (using yaml-config) nested:
list:
- not-ok: [] # This is considered as missing/unmappable |
This is because we comply with the MicroProfile Config specification. The specification, states the behavior for boxes primitives / String configuration for Arrays and Lists here: https://github.com/eclipse/microprofile-config/blob/master/spec/src/main/asciidoc/configexamples.asciidoc#config-value-conversion-rules. Both Map and complex type List, are only available in SmallRye Config, so no rules are specified for these cases. I understand that it may be inconsistent with other properties. We could make both cases have the same behavior to other properties, but also get some questions we need to answer:
One additional point on inconsistency is how MicroProfile Config adds support for Arrays / Collections. There is only support for single elements, and the configuration values are set using a comma-separated string. Obviously, this is not suited for Collections of nested elements types. In this case, MicroProfile Config, does mandate the config property to exist, but due to the nature of how it is defined, it is easy to resolve and report to the user. |
Describe the bug
Using Quarkus configuration, specifically
@ConfigMapping
:Set
(most likely aList
too) cannot be empty, but must be wrapped inside anOptional
if one wants a "default empty" behaviorMap
cannot be wrapped in anOptional
, but is empty by defaultThat is confusing.
Expected behavior
A less confusing approach.
I would argue that Lists, Maps, and Optionals (which can all be streamed) are empty by default.
However, I would absolutely expect that if I can/must have
Optional<Set<>>
, then I can also haveOptional<Map<>>
.Actual behavior
It is confusing.
How to Reproduce?
Use try to use:
Output of
uname -a
orver
Linux brocken 5.19.9-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep 15 09:49:52 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Output of
java -version
openjdk version "17.0.4.1" 2022-08-12 OpenJDK Runtime Environment (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1) OpenJDK 64-Bit Server VM (Red_Hat-17.0.4.1.1-1.fc36) (build 17.0.4.1+1, mixed mode, sharing)
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.12.3.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739) Maven home: /home/jreimann/tools/maven/apache-maven-current Java version: 17.0.4.1, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-17-openjdk-17.0.4.1.1-1.fc36.x86_64 Default locale: en_IE, platform encoding: UTF-8 OS name: "linux", version: "5.19.9-200.fc36.x86_64", arch: "amd64", family: "unix"
Additional information
No response
The text was updated successfully, but these errors were encountered: