IllegalStateException:无法覆盖 Guava map.put 中的原因
我使用 This 似乎工作正常创建地图
new MapMaker().softValues().maximumSize(cacheSize).makeMap();
,但是,在服务器上部署并将新元素放入地图后立即访问后,有时会出现以下异常:
java.lang.IllegalStateException: Can't overwrite cause
at java.lang.Throwable.initCause(Throwable.java:320)
at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:624)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:474)
at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at com.google.common.collect.CustomConcurrentHashMap$2.iterator(CustomConcurrentHashMap.java:828)
at java.util.AbstractCollection.remove(AbstractCollection.java:241)
at com.google.common.collect.CustomConcurrentHashMap$Segment.removeFromChain(CustomConcurrentHashMap.java:2599)
at com.google.common.collect.CustomConcurrentHashMap$Segment.processPendingCleanup(CustomConcurrentHashMap.java:2772)
at com.google.common.collect.CustomConcurrentHashMap$Segment.runLockedCleanup(CustomConcurrentHashMap.java:2860)
at com.google.common.collect.CustomConcurrentHashMap$Segment.preWriteCleanup(CustomConcurrentHashMap.java:2806)
at com.google.common.collect.CustomConcurrentHashMap$Segment.put(CustomConcurrentHashMap.java:2374)
at com.google.common.collect.CustomConcurrentHashMap.put(CustomConcurrentHashMap.java:3346)
at my.app.cache.CacheImplGoogleGuava.put(CacheImplGoogleGuava.java:36)
...
可能是什么原因?
--- 更新:
JBoss 版本为 5。
在 Throwable.initCause 中设置断点会显示 ClassNotFoundException
并显示消息: com.google.common.collect.Iterators 的已销毁类加载器的使用无效,UCL 已销毁于:
使用 Stacktrace
ClassNotFoundException(Throwable).initCause(Throwable):320
UnifiedClassLoader3(RepositoryClassLoader).findClass(String):628
...
UnifiedClassLoader3(ClassLoader).loadClass(String):248
CustomConcurrentHashMap$2.iterator():828
CustomConcurrentHashMap$2(AbstractCollection<E>).remove(Object):241
CustomConcurrentHashMap$Segment.enqueueCleanup(...):2738
CustomConcurrentHashMap$Segment.unsetValue(...):2662
CustomConcurrentHashMap<K, V>.reclaimValue(...)
CustomConcurrentHashMap$SoftValueReference<K, V>.finalizeReferent():1637
...
Method.invoke:574
Finalizer.claenUp:154
Finalizer.run:127
从堆栈跟踪中,似乎映射中的一个对象已完成,而在 finalizeReferent
中,无法加载类 com.google.common.collect.Iterators
。
I create a map using
new MapMaker().softValues().maximumSize(cacheSize).makeMap();
This seemed to work fine, however, I sometimes get the following exception after accessing right after deploying on the server and putting new elements into the map:
java.lang.IllegalStateException: Can't overwrite cause
at java.lang.Throwable.initCause(Throwable.java:320)
at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:624)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:474)
at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at com.google.common.collect.CustomConcurrentHashMap$2.iterator(CustomConcurrentHashMap.java:828)
at java.util.AbstractCollection.remove(AbstractCollection.java:241)
at com.google.common.collect.CustomConcurrentHashMap$Segment.removeFromChain(CustomConcurrentHashMap.java:2599)
at com.google.common.collect.CustomConcurrentHashMap$Segment.processPendingCleanup(CustomConcurrentHashMap.java:2772)
at com.google.common.collect.CustomConcurrentHashMap$Segment.runLockedCleanup(CustomConcurrentHashMap.java:2860)
at com.google.common.collect.CustomConcurrentHashMap$Segment.preWriteCleanup(CustomConcurrentHashMap.java:2806)
at com.google.common.collect.CustomConcurrentHashMap$Segment.put(CustomConcurrentHashMap.java:2374)
at com.google.common.collect.CustomConcurrentHashMap.put(CustomConcurrentHashMap.java:3346)
at my.app.cache.CacheImplGoogleGuava.put(CacheImplGoogleGuava.java:36)
...
What could be the reason?
--- Updated:
JBoss version is 5.
Setting a breakpoint in Throwable.initCause revealed ClassNotFoundException
with message:Invalid use of destroyed classloader for com.google.common.collect.Iterators, UCL destroyed at:
and with Stacktrace
ClassNotFoundException(Throwable).initCause(Throwable):320
UnifiedClassLoader3(RepositoryClassLoader).findClass(String):628
...
UnifiedClassLoader3(ClassLoader).loadClass(String):248
CustomConcurrentHashMap$2.iterator():828
CustomConcurrentHashMap$2(AbstractCollection<E>).remove(Object):241
CustomConcurrentHashMap$Segment.enqueueCleanup(...):2738
CustomConcurrentHashMap$Segment.unsetValue(...):2662
CustomConcurrentHashMap<K, V>.reclaimValue(...)
CustomConcurrentHashMap$SoftValueReference<K, V>.finalizeReferent():1637
...
Method.invoke:574
Finalizer.claenUp:154
Finalizer.run:127
From the stacktrace, it seems as if an object in the map was finalized where in finalizeReferent
the class com.google.common.collect.Iterators
cannot be loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一般来说,您的问题似乎与 MapMaker 或 Guava 无关。
您只能看到在处理另一个异常时发生的异常(不幸的是)。
当已经为当前
Throwable
指定了原因(通过方法或构造函数)时调用Throwable.initCause()
会引发异常。RepositoryClassLoader.findClass()
方法似乎正在处理一些它期望没有原因的异常,但实际上它已经设置了一个原因,这会触发此异常,不幸的是,您在这里看到的异常隐藏了实际的异常 。 (这对于解决问题可能更为重要)
尝试在第 320 行的
Throwable.initCause()
或RepositoryClassLoader.findClass()
处放置一个断点(在第 624 行)并重现问题以(希望)在 IDE 的局部变量视图中看到“真正的”异常。Your problem seems to be unrelated to
MapMaker
or Guava in general.You only see an exception that happens while handling another exception (unfortunately).
Throwable.initCause()
throws an exception when it's called while there was already a cause specified for the currentThrowable
(either via the method or the constructor`.The
RepositoryClassLoader.findClass()
method seems to be handling some exception that it expects not to have a cause, but in fact it already has a cause set, which triggers this exception.Unfortunately the exception you see here hides the actual exception (which would probably be much more important for solving the problem).
Try to put a breakpoit at
Throwable.initCause()
at line 320 or atRepositoryClassLoader.findClass()
(at line 624) and reproduce the problem to (hopefully) see the "real" exception in the local variables view of your IDE.这似乎是一个已知的 JBoss 错误,可能已在该平台的新版本中得到解决。这里至少有一个类似的错误:
JBREM-552:无法初始化 ClassCastException 的原因
您可能会尝试升级您的 JBoss 版本(尽管这个特定的错误意味着修复是在 2006 年),或者如果您的版本是最新的,则提交另一个错误。可能是修复很草率,只修复了该错误的作者报告的一种情况,而不是类似的情况。
This seems to be a known JBoss bug that might have already been resolved in new versions of the platform. Here is at least one similar bug:
JBREM-552: cannot init cause of ClassCastException
You might try upgrading your version of JBoss (though this particular bug implies the fix was in 2006) or filing another bug if your version is up to date. It could be the fix was sloppy and only fixed the one case that the author of that bug reported, and not similar cases.