Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get String[] Size in Velocity

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2018

Having trouble getting the size of a passed in String[] object. I can access individual elements fine with "$var[x]", but trying "$var.size()" results in a NullPointerException being thrown by the velocity template object.

Am I misunderstanding the docs? Or does JIRA not use Velocity 1.7?

2 answers

0 votes
Nir Haimov
Community Champion
October 14, 2018

Hi @Jackson Farnsworth

Yes, Jira use velocity.

If both $var.size() and $var.length() comes with the same error,

Then you better check that you pass/access your "var" correctly...

Nir Haimov
Community Champion
October 15, 2018

@Jackson Farnsworth

Try also ".size()" or ".size"

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 29, 2018

None of these seem to work. I just switched to using an ArrayList<String> object. That seems to have worked fine.

0 votes
JP _AC Bielefeld Leader_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 12, 2018

Hi Jackson,

Confluence uses Velocity, not sure about Jira. Try $var.length()

Best

JP

Nir Haimov
Community Champion
October 14, 2018

.

Jackson Farnsworth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 15, 2018

I've tried ".length" and ".length()", both being displayed as text instead of being interpreted. I've used ".getClass()" to confirm that the variable being passed in is a String[]

Suggest an answer

Log in or Sign up to answer