Fix java.lang.ClassCastException is reading default yaml config#3920
Conversation
…o java.lang.String"
|
An alternative approach would be to change the fun Config.valueOrDefaultCommaSeparated(
key: String,
default: List<String>
): List<String> {
fun fallBack() = valueOrDefault(key, default.joinToString(","))
.trim()
.commaSeparatedPattern(",", ";")
.toList()
return try {
valueOrDefault<List<Any>>(key, default).map { it.toString() }
} catch (_: IllegalStateException) {
fallBack()
} catch (_: ClassCastException) {
fallBack()
}
} |
|
On second thought... Your solution is probably the safer bet for now. Since we only support lists that are parameterized with |
I'd say let's go for that 👍 This PR is sort of crucial as it's currently blocking the release of |
|
The expectation in |
marschwar
left a comment
There was a problem hiding this comment.
I am so glad that you came across this before the release. Thank you
Codecov Report
@@ Coverage Diff @@
## main #3920 +/- ##
============================================
- Coverage 83.59% 83.44% -0.15%
- Complexity 3123 3149 +26
============================================
Files 456 456
Lines 9015 9014 -1
Branches 1754 1754
============================================
- Hits 7536 7522 -14
- Misses 564 565 +1
- Partials 915 927 +12
Continue to review full report at Codecov.
|
Stacktrace
Root cause
With #3827, each line in a multi-line YAML array can be unquoted, such as
This will lead to YAML config being parsed as
List<Int>, butMagicNumber.ignoreValues()still have a default value ofList<String>, causing the exception.Fix
The pessimistic fix is to always print quotes in multi-line YAML array.
Testing
Since Gradle integration tests are only testing against latest published version, I have verified the fix through: