【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

Spring接受前台的数据超过256出现如下异常:

org.springframework.beans.InvalidPropertyException: Invalid property 'specificationValues[256]' of bean class [com.sencloud.entity.Specification]: Index of out of bounds in property path 'specificationValues[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
	org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:811)
	org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:554)

溯源了下Spring的代码,找到了DataBinder,先解释下DataBinder类的作用,见链接

http://docs.spring.io/spring/docs/1.2.x/api/org/springframework/validation/DataBinder.html

其中有一句

Binder that allows for binding property values to a target object. The binding process can be customized through specifying allowed fields, required fields, and custom editors.

Note that there are potential security implications in failing to set an array of allowed fields. In the case of HTTP form POST data for example, malicious clients can attempt to subvert an application by supplying values for fields or properties that do not exist on the form. In some cases this could lead to illegal data being set on command objects or their nested objects. For this reason, it is highly recommended to specify the allowedFields property on the DataBinder.

大概意思是前台的Form 元素绑定到 后台的JaveBean对象,做的一个映射,但是这个映射的List长度不可以超过256

反编译的源码如下:

解决如下:重set下autoGrowCollectionLimit,当做绑定的时候set为1024或者更大

  /**
     * 由于Spring在接受前台传入的List时,就会出现256的IndexOutOfBoundsException异常
     * 设置setAutoGrowCollectionLimit为1024
     * @param binder
     * @see [类、类#方法、类#成员]
     */
    @InitBinder
    public void initListBinder(WebDataBinder binder)
    {
        // 设置需要包裹的元素个数,默认为256
        binder.setAutoGrowCollectionLimit(1024);
    }

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-12 22:47:04

【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256的相关文章

报错: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

描述:使用Hibernate登陆验证时故意输入没有的用户名,所产生的错误. 错误代码: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /*      * 根据客户的用户名查找客户信息      */     @Override     public User getUserByUserName(String userName) {         String hql="from User where userName=?";         Session s

hive脚本出现Error: java.lang.RuntimeException: Error in configuring object和Caused by: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

是在reduce阶段报的错误,详细错误信息是 朱传豪 19:04:48 Diagnostic Messages for this Task: Error: java.lang.RuntimeException: Error in configuring object at org.apache.hadoop.util.ReflectionUtils.setJobConf(ReflectionUtils.java:109) at org.apache.hadoop.util.ReflectionU

常见异常(1)— java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

异常: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 原因:对于一个list在获取其中的首个元素list.get(0)时,未做判断list是否存在元素的判断 改正:if(null!=list && list.size() !=0){  list.get(0);} 注:list=null 是判断是否存在这样一个list ,list.get(0) 是指list中是否有元素(前提是这个list已经存在) 原文地址:https://w

【Exception】 java.lang.NoSuchMethodError: android.app.AlertDialog$Builder.setOnDismissListener

f(Build.VERSION.SDK_INT >10) builder =newAlertDialog.Builder(getActivity(), R.style.Theme.Sherlock.Dialog);else builder =newAlertDialog.Builder(getActivity());AlertDialog.Builder builder;try{ builder =newAlertDialog.Builder(getActivity(), R.style.The

【Android】java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'.

一.问题 Java调用JS事件出现 java.lang.RuntimeException: java.lang.Throwable: A WebView method was called on thread 'JavaBridge'. All WebView methods must be called on the same thread. (Expected Looper Looper (main, tid 1) {3474c308} called on Looper (JavaBridg

Spring的java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!异常处理方法

使用Spring提供的模板类HibernateDaoSupport,如果单纯的使用'命名参数'的形式编写HQL语句如: 1 public class UserDaoImpl extends HibernateDaoSupport implements IUser { 2 3 4 @Override 5 public User login(String userName, String pwd) { 6 String hql="from User as u where u.username=:us

【转】java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;

最近在配置最新的ssh(struts2.3.16.3+hibernate4.3.7+spring4.1.2)的时候遇到的这个错误提示,后来在网上找了半天都不能解决,虽然有个说法是model对象用这样@Entity(name = "UserInfo")的方式来实现,但是这样的话对象和表明必须一致,后来找到如下原因:希望对大家有所帮助,特分享如下: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/p

【转】java.lang.ClassNotFoundException: org.springframework.context.event.GenericApplicationListener

http://www.cnblogs.com/softidea/p/6064091.html Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/GenericApplicationListener From the above error, application is unable to find the class defined from the jar dependencies. Ge

【异常】java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver 的解决方案

起因:使用htmlunit爬取外部网页的时候遇到这个异常:java.lang.IllegalArgumentException: Cannot locate declared field class org.apache.http.impl.client.HttpClientBuilder.dnsResolver <dependency> <groupId>net.sourceforge.htmlunit</groupId> <artifactId>html