Java – IllegalStateException: unable to overwrite guava map Reasons in put
I use to create a map
new MapMaker().softValues().maximumSize(cacheSize).makeMap();
This seems to work, but after deploying on the server and putting new elements into the map, I sometimes get the following exceptions:
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?
– update:
JBoss version is 5
In throwable Set a breakpoint in initcause and display classnotfoundexception with message: com google. common. collect. Iterators' use of the destroyed class loader is invalid. UCL is destroyed in the following locations: and 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 stack trace, it seems that the objects in the map are finally determined, and the class com.com cannot be loaded in finalizereferent google. common. collect. Iterators.
Solution
Your question seems to have nothing to do with mapmaker or guava
You only see the exception that happens when you handle another exception (unfortunately)
Throwable. Initcause() throws an exception when calling, and has specified a reason for the current throwable (through method or constructor)
RepositoryClassLoader. The findclass () method seems to be handling some exceptions that it expects to have no cause, but in fact it already has a cause set that triggers the exception
Unfortunately, the exceptions you see here hide the actual exceptions (which may be more important for solving the problem)
Try in throwable Initcause() line 320 or repository classloader Findclass() (line 624) places a breakpoit and reproduces the problem (hopefully) to see a "real" exception in the IDE's local variables view