Skip to content

Mustache template evaluation failure for non-existent array indices #55200

Closed
@ywangd

Description

@ywangd

When mustache expression requests an item with a non-existent index from a Collection object, an IndexOutOfBoundsException will be thrown which in turn results in template execution failure.

The mustache java library does not support indexing into Collection object. This feature is provided by a custom CustomReflectionObjectHandler which wraps a Collection object inside a specialised map of class CustomReflectionObjectHandler#CollectionMap. The exception is thrown when checking whether the given index is available in the collection through the Map#containsKey method, whose implementation is simply trying to retrieve the item at given index. Therefore when the index does not exist, an IndexOutOfBoundsException will be thrown.

Mustache is in general very lenient of missing items. When an item does not exist, it will be simply rendered as empty string. Hence there are values to have a consistent behaviour for collection items. On the flipside, it is worth note that silently ignore all missing items could be a separate issue on its own.

Metadata

Metadata

Assignees

Labels

:Core/Infra/ScriptingScripting abstractions, Painless, and MustacheTeam:Core/InfraMeta label for core/infra teamtriagedIssue has been looked at, and is being left open

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions