播放1.2.5 ConcurrentModification异常

时间:2015-07-09 11:46:08

标签: java playframework

Plya logs(1.2.5)Java中的奇怪多个异常。有这种行为的原因吗?

play.exceptions.UnexpectedException: Unexpected Error
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:264)
        at play.server.ServletWrapper$ServletInvocation.execute(ServletWrapper.java:561)
        at play.Invoker$Invocation.run(Invoker.java:278)
        at play.server.ServletWrapper$ServletInvocation.run(ServletWrapper.java:552)
        at play.Invoker.invokeInThread(Invoker.java:68)
        at play.server.ServletWrapper.service(ServletWrapper.java:143)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ConcurrentModificationException
        at java.util.ArrayList.sort(ArrayList.java:1456)
        at java.util.Collections.sort(Collections.java:175)
        at play.mvc.ActionInvoker.handleAfters(ActionInvoker.java:335)
        at play.mvc.ActionInvoker.invoke(ActionInvoker.java:210)
        ... 22 more

ActionInvoker.java

private static void handleAfters(Http.Request request) throws Exception {
    List<Method> afters = Java.findAllAnnotatedMethods(Controller.getControllerClass(), After.class);
    Collections.sort(afters, new Comparator<Method>() {

        public int compare(Method m1, Method m2) {
            After after1 = m1.getAnnotation(After.class);
            After after2 = m2.getAnnotation(After.class);
            return after1.priority() - after2.priority();
        }
    });
    ControllerInstrumentation.stopActionCall();
    for (Method after : afters) {
        String[] unless = after.getAnnotation(After.class).unless();
        String[] only = after.getAnnotation(After.class).only();
        boolean skip = false;
        for (String un : only) {
            if (!un.contains(".")) {
                un = after.getDeclaringClass().getName().substring(12) + "." + un;
            }
            if (un.equals(request.action)) {
                skip = false;
                break;
            } else {
                skip = true;
            }
        }
        for (String un : unless) {
            if (!un.contains(".")) {
                un = after.getDeclaringClass().getName().substring(12) + "." + un;
            }
            if (un.equals(request.action)) {
                skip = true;
                break;
            }
        }
        if (!skip) {
            after.setAccessible(true);
            inferResult(invokeControllerMethod(after));
        }
    }
}

更新

看起来findAllAnnotatedMethods从缓存返回原始Collection,结果排序抛出CME。此方法应该返回复制。它是在以后的版本中修复的吗?

在Play中修补一个类的最简单方法是什么?考虑到我们正在为Tomcat构建WAR

0 个答案:

没有答案