valueOrDefaultCommaSeparated throws a ClassCastException #2566
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix #2561
Ok bear with me, this is complex. This is a bug added in #2474. The reason of that PR is described at #2463.
When
ForbiddenImport
executes the extension functionConfigAware.valueOrDefaultCommaSeparated
the actual implementation that we are using isDisabledAutoCorrectConfig
. ButDisabledAutoCorrectConfig
does nearly nothing here. It just delegate the work toCompositeConfig
.This is the code that is executed there:
https://github.com/arturbosch/detekt/blob/91fdc64fecb858045059bf544fa9bfb6017c8c1d/detekt-api/src/main/kotlin/io/gitlab/arturbosch/detekt/api/internal/CompositeConfig.kt#L15-L16
The problem is that
lookFirst.valueOrNull(key)
returns aString
butT
is aList<String>
. So we and with a function that should return a List returning""
. This is not flagged by the compiler because we are doing a lot of casting in this part of the code.The type is checked in the line 46 after the function is called
https://github.com/arturbosch/detekt/blob/91fdc64fecb858045059bf544fa9bfb6017c8c1d/detekt-rules/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/Junk.kt#L40-L52
and, of course, it crash with a
ClassCastException
.For this reason it's safe to catch the
ClassCastException
too and try again asString
. Does it have sense?Tests pending... I'm figuring out how to test this...