由于javax.validation异常导致concurrentmodification异常

mwngjboj  于 2021-07-14  发布在  Java
关注(0)|答案(2)|浏览(449)

我正面临这样一个奇怪的问题:由于javax.validation问题,api抛出了并发修改异常。

java.util.ConcurrentModificationException: null
    at java.util.HashMap$HashIterator.nextNode(HashMap.java:1445) ~[na:1.8.0_265]
    at java.util.HashMap$ValueIterator.next(HashMap.java:1474) ~[na:1.8.0_265]
    at org.eclipse.persistence.jpa.PersistenceProvider.isLoadedWithReference(PersistenceProvider.java:464) ~[eclipselink-2.6.1.jar:2.6.1.v20150916-55dc7c3]
    at javax.persistence.Persistence$PersistenceUtilImpl.isLoaded(Persistence.java:154) ~[javax.persistence-2.1.0.jar:2.1.0]
    at org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.isReachable(JPATraversableResolver.java:56) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver.isReachable(DefaultTraversableResolver.java:130) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.resolver.SingleThreadCachedTraversableResolver.isReachable(SingleThreadCachedTraversableResolver.java:46) ~[bean-validator-2.2.0.jar:5.0.0.Final] [1 skipped]
    at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1307) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1292) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    ... 49 common frames omitted
Wrapped by: javax.validation.ValidationException: HV000041: Call to TraversableResolver.isReachable() threw an exception.
    at org.hibernate.validator.internal.engine.ValidatorImpl.isReachable(ValidatorImpl.java:1316) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.isValidationRequired(ValidatorImpl.java:1292) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraint(ValidatorImpl.java:475) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForDefaultGroup(ValidatorImpl.java:424) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateConstraintsForCurrentGroup(ValidatorImpl.java:388) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:340) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:524) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateInContext(ValidatorImpl.java:349) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraint(ValidatorImpl.java:635) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateCascadedConstraints(ValidatorImpl.java:524) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateParametersInContext(ValidatorImpl.java:916) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:240) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.hibernate.validator.internal.engine.ValidatorImpl.validateParameters(ValidatorImpl.java:198) ~[bean-validator-2.2.0.jar:5.0.0.Final]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095) [webapp-runner.jar:na] [28 skipped]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) [webapp-runner.jar:na]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502) [webapp-runner.jar:na]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458) [webapp-runner.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_265]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_265]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [webapp-runner.jar:na]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_265]

堆栈跟踪没有说明bean中的哪个验证导致了问题。

qyyhg6bp

qyyhg6bp1#

显然,异常堆栈跟踪表明hashmap中发生了并发修改异常。如果您在遍历非线程安全的Map值或api时使用迭代器(如泛型hashmap对象),则会发生并发修改异常。尝试使用并发hashmap,您的问题就会得到解决。

omvjsjqw

omvjsjqw2#

看起来stacktrace的格式很特别。。。一些东西。
通常的显示方法是先显示主异常,然后显示 cause (或 Package )例外链。但是您向我们展示的是 Package 的异常,后面是 Package 它的异常。
这意味着 ConcurrentModificationException 导致了 ValidationException ... 而不是相反。
不幸的是,这并不能解释到底发生了什么。

相关问题