Ticket #374 (new enhancement)

Opened 3 years ago

Last modified 3 years ago

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:1 Changed 3 years ago by mpo

Please add a sample/testcase with as little other fuzz as possible

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:3 Changed 3 years ago by jgou

  • Milestone set to 0.4

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

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)

comment:7 Changed 3 years ago by karel

(In [1755]) Dont give [index out of bounds] when trying to format the 0'th element of an empty array.

This is a rather silly workaround for an upstream bug (see #374)

Note: See TracTickets for help on using tickets.