Clustered Wildfly 抛出 java.lang.IllegalAccessError

Clustered Wildfly throws java.lang.IllegalAccessError

我在 Wildfly 托管域上 运行ning 应用程序,该域由 2 个虚拟机组成,每个 VM 上有 3 个服务器。

异常发生在console.log:

14:04:10,254 WARN  [org.jboss.weld.Servlet] (default task-51) WELD-000717: Unable to deactivate context org.jboss.weld.context.http.HttpRequestContextImpl@2ec2ea52 when destroying request HttpServletRequestImpl [ GET /orpon/ ]
14:04:10,254 WARN  [org.jboss.weld.Servlet] (default task-51) WELD-000717: Unable to deactivate context org.jboss.weld.context.http.HttpSessionContextImpl@f171e22 when destroying request HttpServletRequestImpl [ GET /orpon/ ]
14:04:10,254 ERROR [io.undertow.request] (default task-51) Undertow request failed HttpServerExchange{ GET /orpon/}: java.lang.IllegalAccessError: Can not set final int field io.undertow.util.HttpString.hashCode to (int)-1978065285
    at io.undertow.util.HttpString.readObject(HttpString.java:340)
    at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source) [:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_66]
    at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_66]
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1644)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:149)
    at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:135)
    at org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:53)
    at org.jboss.marshalling.river.RiverObjectInputStream.readObjectOverride(RiverObjectInputStream.java:307)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:365) [rt.jar:1.8.0_66]
    at java.util.HashMap.readObject(HashMap.java:1394) [rt.jar:1.8.0_66]
    at sun.reflect.GeneratedMethodAccessor157.invoke(Unknown Source) [:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_66]
    at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_66]
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:224)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1745)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1658)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:149)
    at org.jboss.marshalling.river.BlockUnmarshaller.readObject(BlockUnmarshaller.java:135)
    at org.jboss.marshalling.MarshallerObjectInputStream.readObjectOverride(MarshallerObjectInputStream.java:53)
    at org.jboss.marshalling.river.RiverObjectInputStream.readObjectOverride(RiverObjectInputStream.java:307)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:365) [rt.jar:1.8.0_66]
    at java.util.HashMap.readObject(HashMap.java:1396) [rt.jar:1.8.0_66]
    at sun.reflect.GeneratedMethodAccessor157.invoke(Unknown Source) [:1.8.0_66]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_66]
    at java.lang.reflect.Method.invoke(Method.java:497) [rt.jar:1.8.0_66]
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:307)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1637)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1285)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:276)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
    at org.wildfly.clustering.marshalling.SimpleMarshalledValue.get(SimpleMarshalledValue.java:101)
    at org.wildfly.clustering.marshalling.SimpleMarshalledValue.get(SimpleMarshalledValue.java:45)
    at org.wildfly.clustering.marshalling.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:45)
    at org.wildfly.clustering.marshalling.MarshalledValueMarshaller.read(MarshalledValueMarshaller.java:32)
    at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionFactory.findValue(CoarseSessionFactory.java:127)
    at org.wildfly.clustering.web.infinispan.session.coarse.CoarseSessionFactory.findValue(CoarseSessionFactory.java:56)
    at org.wildfly.clustering.web.infinispan.session.InfinispanSessionManager.findSession(InfinispanSessionManager.java:232)
    at org.wildfly.clustering.web.undertow.session.DistributableSessionManager.getSession(DistributableSessionManager.java:115)
    at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:723)
    at io.undertow.servlet.spec.ServletContextImpl.getSession(ServletContextImpl.java:753)
    at io.undertow.servlet.spec.ServletContextImpl.updateSessionAccessTime(ServletContextImpl.java:757)
    at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:548)
    at io.undertow.servlet.spec.HttpServletResponseImpl.doErrorDispatch(HttpServletResponseImpl.java:162)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:317)
    at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:261)
    at io.undertow.servlet.handlers.ServletInitialHandler.access[=11=]0(ServletInitialHandler.java:80)
    at io.undertow.servlet.handlers.ServletInitialHandler.handleRequest(ServletInitialHandler.java:172)
    at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199)
    at io.undertow.server.HttpServerExchange.run(HttpServerExchange.java:774)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_66]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_66]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_66]

我正在尝试 运行 在 wildfly 8.2.1.Final 和 9.0.2 Final 上使用 openjdk-1.8 和 Oracle jdk-1.8 应用程序结果。应用程序已部署并且 运行 没有错误,我已成功登录并通过负载平衡器(循环法)在服务器上工作。

In undertow sources at github class io.undertow.util.HttpString 的字段 hashCode 声明为 final transient int。为什么 readObject 方法试图以非常奇怪的方式更改此字段的值?

我在 Internet 上进行了搜索,但没有发现任何关于此错误或类似错误的信息,也不知道该如何处理。

在我的应用程序中,属于此异常的地方可能在哪里?

更新: Undertow server 的这个补丁帮助我避免了问题:

From 7083c4145878f954bbde14f1f6acbb31414c88d9 Mon Sep 17 00:00:00 2001
From: fedor patlin <patlin.f@sovzond.center>
Date: Fri, 18 Dec 2015 15:55:32 +0500
Subject: [PATCH] Set field hashCodeField accessible

---
 core/src/main/java/io/undertow/util/HttpString.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/core/src/main/java/io/undertow/util/HttpString.java b/core/src/main/java/io/undertow/util/HttpString.java
index cc75a0b..d21257c 100644
--- a/core/src/main/java/io/undertow/util/HttpString.java
+++ b/core/src/main/java/io/undertow/util/HttpString.java
@@ -335,7 +335,9 @@ public final class HttpString implements Comparable<HttpString>, Serializable {
     private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
         ois.defaultReadObject();
         try {
+            hashCodeField.setAccessible(true);
             hashCodeField.setInt(this, calcHashCode(bytes));
+            hashCodeField.setAccessible(false);
         } catch (IllegalAccessException e) {
             throw new IllegalAccessError(e.getMessage());
         }
-- 
2.5.0

这已在 Wildfly 中修复,请参阅 fix