No modifications are allowed to a locked ParameterMap

简介: 错误:java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap at org.apache.catalina.util.ParameterMap.remove(ParameterMap.java:205) 1.Servlet中使用了这个方法:request.getParameterMap(),将它的返回值赋值给一个空的hashmap对象结果报错。
错误: java.lang.IllegalStateException: No modifications are allowed to a locked ParameterMap

at org.apache.catalina.util.ParameterMap.remove(ParameterMap.java:205)

1.Servlet中使用了这个方法:request.getParameterMap(),将它的返回值赋值给一个空的hashmap对象结果报错。参考:

it looks like you are trying to *modify* the > received form parameters Map, which under Tomcat's interpretation of > HTTP request handling is a no-no. (The Servlet Spec 3.0 does not > explicitly say so (Chapter 3), but strongly hints in that direction > (there are only "get" methods, no "set" ones).

貌似Servlet规范隐晦的告诉了我们这点。

The relevant info is in the Javadoc for ServletRequest#getParameterMap(). It states quite clearly that the parameter map is immutable.

这个方法的返回值是不可变的。

作者还说一些关键信息却只能在javadoc里找到真是令人抓狂啊~

2.解决方法是:new HashMap(request.getParameterMap())

因为直接用等好赋值只是地址引用,并未改变内存空间,因此无法对之前产生的那个被锁定的map对象进行操作,而使用new方法确实重新申请了内存地址,将该“不可变”的map对象复制到另一个域空间里。

参考:

1.http://goo.gl/pvweu

2.http://goo.gl/AEvPN

 

https://my.oschina.net/cwalet/blog/35431

 

不能被修改的原因:

org.apache.catalina.util.ParameterMap

 /**
     * Associate the specified value with the specified key in this map.  If
     * the map previously contained a mapping for this key, the old value is
     * replaced.
     *
     * @param key Key with which the specified value is to be associated
     * @param value Value to be associated with the specified key
     *
     * @return The previous value associated with the specified key, or
     *  <code>null</code> if there was no mapping for key
     *
     * @exception IllegalStateException if this map is currently locked
     */
    @Override
    public V put(K key, V value) {

        if (locked)
            throw new IllegalStateException
                (sm.getString("parameterMap.locked"));
        return (super.put(key, value));

    }

 

相关文章
|
4月前
|
关系型数据库 MySQL 数据安全/隐私保护
问题:ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
问题:ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
32 0
|
5月前
|
安全 关系型数据库 MySQL
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements问题处理
【5月更文挑战第8天】ERROR 1819 (HY000): Your password does not satisfy the current policy requirements问题处理
53 2
|
5月前
|
安全 关系型数据库 MySQL
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
37 2
|
11月前
|
存储 API Python
UnicodeEncodeError和surrogates not allowed
UnicodeEncodeError和surrogates not allowed
|
关系型数据库 MySQL 数据库
Your password has expired. To log in you must change it using a client that supports expired passwod
Your password has expired. To log in you must change it using a client that supports expired passwod错误解决
Your password has expired. To log in you must change it using a client that supports expired passwod
|
安全 对象存储
set_time_limit() has been disabled for security reasons
set_time_limit() has been disabled for security reasons
162 0
set_time_limit() has been disabled for security reasons
|
关系型数据库 MySQL 数据安全/隐私保护
|
关系型数据库 MySQL Java
Connection is read-only. Queries leading to data modification are not allowed
看了下mysql-connector-5.1.40版本中,如果设置failoverReadOnly=true (即默认值,参考链接),当mysql连接failover时,会根据jdbc连接串将当前连接的readOnly值设置为true (第8行代码) 1 2 3 4 ...
3409 0