[2.0.x - Java] Index Out of Bounds Exception when binding form data

837 views
Skip to first unread message

Anthony Luxton

unread,
Aug 13, 2012, 12:25:41 PM8/13/12
to play-fr...@googlegroups.com
Hi, I have spent most of the day debugging an IndexOutOfBoundsException resulting when binding a posted form with a large number of inputs to a Class containing a list. The error occurs when indices larger than the list size are used on add. The default size seems to be 255.

I have resolved the issue using the apache Commons Collections GrowthList which dynamically grows the list:
 
import org.apache.commons.collections.list.GrowthList;
import org.apache.commons.collections.*;
...
  public static Result maxFormPost() { 
    Form<AddForm> filledForm = form(AddForm.class).bindFromRequest();
    return TODO;
  }
  
  public static class AddForm {
    //public List<String> form = GrowthList.decorate( new ArrayList() );
    
  }

 I thought I would post it here as firstly I found no reference to the problem when searching and hope it might be helpful for others troubleshooting and also as I am wondering if this is the correct fix. Or have I missed something obvious?

Thanks
Ant

juhi jariwala

unread,
Mar 30, 2014, 8:51:36 AM3/30/14
to play-fr...@googlegroups.com
Hi, I am facing same problem can you give me more description about this solution.
Thanks
Juhi 

Mateusz Szczap

unread,
Mar 30, 2014, 10:43:17 AM3/30/14
to play-fr...@googlegroups.com
I have seen a similar problem when binding arrays but when I switched an array to a list problem disappeared. I was debugging the code and I would say it wasn't clear to me why play + spring binding cannot handle Arrays of primitives, e.g. strings.

co...@eyeviewdigital.com

unread,
Apr 1, 2014, 2:39:55 PM4/1/14
to play-fr...@googlegroups.com
Hi Anthony,
Here we had the same issue regarding a list and the bind method. The only solution turned out to be using a hashmap instead of a list. For some reason play framework cannot handle indexes greater than 255. Not exactly sure why. Sorry this answer isn't very informative as I'm not exactly sure about the internal reasons.

Shweta Turakhia

unread,
Aug 25, 2014, 6:05:50 PM8/25/14
to play-fr...@googlegroups.com
I have a similar issue and I cannot change the list to map as that is not owned by my team. Was anyone else able to fix this without changing the data structure ? 

Thiago Lima

unread,
Jan 6, 2015, 4:36:51 PM1/6/15
to play-fr...@googlegroups.com
This seems to be the exact same issue as described in http://forum.spring.io/forum/spring-projects/web/119266-setautogrowcollectionlimit-more-than-256-records. The pure Spring solution is described in the link, but I have no idea how to apply it to Play. Btw, I'm facing the same problem, even using Play 2.2.1 (Java).

Erol Merdanović

unread,
Jan 7, 2015, 3:23:53 AM1/7/15
to play-fr...@googlegroups.com
This was already discussed https://github.com/playframework/playframework/issues/3334

As my recommended solution, user request.body and manually parse values.
Reply all
Reply to author
Forward
0 new messages