Ticket #374 (new enhancement)
I18N null formatted as [param index out of bound]
| Reported by: | bc | Owned by: | mpo |
|---|---|---|---|
| Priority: | major | Milestone: | 0.4 |
| Component: | < I18N | Version: | |
| Keywords: | Cc: | kauri-discuss@… |
Description
When you want to format a date which is null you get [param index out of bound] as output. Maybe we can format this as an empty string?
Change History
comment:2 Changed 3 years ago by bc
To reproduce this, change the following line
<t:variable name="now" value="$g{new Date()}"/>
to
<t:variable name="now" value="$g{(Date)null}"/>
In the kauri-i18n-sample in the file index.html.xml
comment:4 Changed 3 years ago by karel
Analysis: the (Date) cast makes no difference. During el evaluation,
the null value is converted into an empty Object[]. (Maybe to make sure it match the format method signature).
The format function then says [param index out of bounds] because the empty Object[] does not have an element at index 0.
Changing the (jboss) el implementation is probably not in the scope of this ticket.
Workaround: test for null values in your template:
${format('{0,date}', empty nullvalue?"-":nullvalue)}
comment:5 Changed 3 years ago by karel
Upstream (jboss-el) bug: https://jira.jboss.org/browse/JBSEAM-2997
comment:6 Changed 3 years ago by karel
The upstream bug actually means that any format invocation which uses more than two arguments is going to fail (${format(str, param1, param2)}) because jboss will not find the varargs method.
I'm adding a workaround (just for the originally reported error) for now,
but we might consider juel (as suggested elsewhere)
Please add a sample/testcase with as little other fuzz as possible