Codec order is not respected by default
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
Codecs are intended to support an "order" property, but this is not correctly respected by the DefaultCodecLookup. This implies that it is impossible to override one codec with another with the same name, unless they just happen to load in the order desired.
In DefaultCodecLookup .registerCodecs() when called from the default startup events, the codecs are retrieved and sorted using OrderComparator.INSTANCE. However, at this point the codec order in DefaultGrailsCodecClass has not yet been initialized, and is the default of 100+instantiationCounter.
Consequently, adding an order property/getter on a *Codec class is not respected unless the codec is preinitialized in some way, or initialization is triggered twice. This does mean that there is an easy (and computationally cheap) workaround: simply call applicationContext.getBean('codecLookup', DefaultCodecLookup).reInitialize() again during application startup. However, it seems that it would be better to respect the order property during the first initialization.
Contributor guide
Research direction
Start in DefaultCodecLookup.registerCodecs(), called during the default startup events, and inspect how it sorts codecs with OrderComparator.INSTANCE before DefaultGrailsCodecClass has initialized its order. Verify that a codec order property/getter is respected during the first initialization, without requiring a second reInitialize() call during application startup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100