enhancement
major
minor
defect
critical
major
minor
minor
#30085
Default values <country value="..."/> and <time-zone value="..."/> (CountryDefaultProvider, TimeZoneDefaultProvider) cannot be used
Description
The default value <country value="DE"/> for an attribute of type tl.util:Country cannot be used. The model fails to load, and the application does not start. The same applies to the default value <time-zone value="Europe/Berlin"/> for an attribute of type tl.util:TimeZone.
Affected: TopLogic 8.0.0-alpha12, unchanged on the current master branch (last change to the class in f8206c98a8, 2023-12-14).
Reproduction
{{{#!xml <property name="country" type="tl.util:Country"> <annotations> <default-value> <country value="DE"/> </default-value> </annotations> </property> }}}
Error on startup
Invalid value 'DE' for property 'value' (com.top_logic.model.provider.BooleanDefaultProvider$Config.getValue()) at file:///WEB-INF/model/....model.xml ... The configuration value 'DE' for the 'value' property is invalid: a Boolean value (true or false) is expected. ... Caused by: com.top_logic.basic.module.ModuleException: Unable to start implementation 'com.top_logic.element.model.DynamicModelService@...'.
Cause
com.top_logic.model.provider.CountryDefaultProvider (module com.top_logic):
{{{#!java @TagName("country") public interface Config extends ConfiguredConstantDefaultProvider.Config<BooleanDefaultProvider> { @Override Country getValue(); } }}}
The type parameter is `BooleanDefaultProvider` instead of `CountryDefaultProvider ` (presumably copied from `BooleanDefaultProvider.Config `). As a result, the configuration is treated as that of `BooleanDefaultProvider`, and `value` is interpreted as a `Boolean`.
Checking the remaining subclasses of `ConfiguredConstantDefaultProvider ` reveals the same copying error in `TimeZoneDefaultProvider ` (<time-zone>). All others (Boolean, Byte, Short, Integer, Long, Float, Double, String, Date, Icon, Color) are correct.
Workaround
For a default country equal to the country of the default locale:
{{{#!xml <default-value> <provider class="com.top_logic.model.provider.DefaultCountryDefault"/> </default-value> }}}
This does not allow you to specify any specific country.
Solution
The configurations for CountryDefaultProvider and TimeZoneDefaultProvider specify their own class as a type parameter:
{{{#!java public interface Config extends ConfiguredConstantDefaultProvider.Config<CountryDefaultProvider> { public interface Config extends ConfiguredConstantDefaultProvider.Config<TimeZoneDefaultProvider> { }}}
This allows <country value="DE"/> and <time-zone value="Europe/Berlin"/> to be used as default values for an attribute.
Test
- test.com.top_logic.model.provider.TestConfiguredConstantDefaultProvider (module com.top_logic) reads the <default-value> annotation with <country>, <time-zone>, and <string>, creates the provider, and checks its class and default value.