You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If invalid value is passed to enum property, we will get a build error: AAPT: error: '420' is incompatible with attribute trp_hourFormat (attr) enum [FORMAT_SYSTEM=0, FORMAT_12=1, FORMAT_24=2]
In runtime, we will get exception with no message:
Caused by: java.lang.IllegalArgumentException
at nl.joery.timerangepicker.TimeRangePicker$HourFormat$Companion.fromId(TimeRangePicker.kt:1160)
at nl.joery.timerangepicker.TimeRangePicker.initAttributes(TimeRangePicker.kt:147)
at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt:114)
at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt:39)
at nl.joery.timerangepicker.TimeRangePicker.<init>(TimeRangePicker.kt)
Library tries to handle such cases but unsuccessfully:
Method fromId never returns null, but throws exception with empty message on invalid value, but initAttributes expects that fromId returns null and assignes default value (HourFormat.FORMAT_12) if returned enum value is null.
So, what's expected behavior? To leave default value, or to throw exception. If the last one, it's better to throw exception with some message like 'Invalid attribute value(trp_hourFormat=value)'
The text was updated successfully, but these errors were encountered:
If invalid value is passed to enum property, we will get a build error:
AAPT: error: '420' is incompatible with attribute trp_hourFormat (attr) enum [FORMAT_SYSTEM=0, FORMAT_12=1, FORMAT_24=2]
Code:
But, nevertheless, if we pass a reference to integer with invalid value, we won't get any build error and code compiles successfully:
ints.xml
activity_main.xml
Full code
In runtime, we will get exception with no message:
Library tries to handle such cases but unsuccessfully:
TimeRangePicker/timerangepicker/src/main/java/nl/joery/timerangepicker/TimeRangePicker.kt
Lines 135 to 140 in a5c73db
TimeRangePicker/timerangepicker/src/main/java/nl/joery/timerangepicker/TimeRangePicker.kt
Lines 1081 to 1086 in a5c73db
Method
fromId
never returns null, but throws exception with empty message on invalid value, butinitAttributes
expects thatfromId
returns null and assignes default value (HourFormat.FORMAT_12
) if returned enum value is null.So, what's expected behavior? To leave default value, or to throw exception. If the last one, it's better to throw exception with some message like 'Invalid attribute value(trp_hourFormat=value)'
The text was updated successfully, but these errors were encountered: