如何修复“java.lang.SecurityException:你不能修改这个地图”

时间:2013-10-24 03:21:50

标签: java multithreading

我有一个例外如下:

2013-10-22 15:16:12 SEVERE Thread-247(247) AspectJExceptionCatcher java.lang.SecurityException: You can not modify this map
    at org.apache.harmony.security.fortress.SecurityUtils.putContext(SecurityUtils.java:78)
    at java.lang.Thread.create(Thread.java:499)
    at java.lang.Thread.<init>(Thread.java:205)
    at com.common.conn.ConnectTask.<init>(ConnectTask.java:80)
    at com.common.conn.CommuTask.<init>(CommuTask.java:43)
    at com.common.conn.ConnectionService$3.sendMsg(ConnectionService.java:144)
    at com.business.favorite.FavorManager.getFolderSong(FavorManager.java:243)
    at com.business.favorite.FavorManager$6.onResult(FavorManager.java:1465)
    at com.common.conn.CommuTask.handleData(CommuTask.java:237)
    at com.common.conn.CommuTask.run(CommuTask.java:209)

在读取SecurityUtils.java代码后,错误是由于该线程已经存在。我的代码确实有这样的逻辑。 CommnuTask是一个线程,在其run()函数流中,它尝试创建其类型的另一个线程。为什么禁止这样做?以及如何解决它?非常感谢。

http://svn.apache.org/repos/asf/harmony/enhanced/java/branches/mrh/drlvm/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/security/fortress/SecurityUtils.java

public static void putContext(Thread thread, AccessControlContext context)
        throws SecurityException {
    if (thread == null) {
        throw new NullPointerException("thread can not be null");
    }
    synchronized (ACC_CACHE) {
        if (ACC_CACHE.containsKey(thread)) {
            throw new SecurityException("You can not modify this map.");
        }
        if (context == null) {
            // this only allowed once - for the very first thread.
            if (ACC_CACHE.containsValue(null)) {
                throw new Error("null context may be stored only once.");
            }
        }
        ACC_CACHE.put(thread, context);
    }
}

0 个答案:

没有答案