4

我在尝试启动码头时遇到以下问题,我得到以下异常:

Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process
[ERROR] org.apache.maven.surefire.testset.TestSetFailedException: java.lang.RuntimeException: com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 51966
[ERROR] at org.apache.maven.surefire.common.junit4.JUnit4RunListener.rethrowAnyTestMechanismFailures(JUnit4RunListener.java:206)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:114)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:85)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:54)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:134)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
[ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
[ERROR] Caused by: java.lang.RuntimeException: com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 51966
[ERROR] at org.apache.maven.surefire.junitcore.TestSet.replay(TestSet.java:100)
[ERROR] at org.apache.maven.surefire.junitcore.ConcurrentRunListener.testSetCompleted(ConcurrentRunListener.java:82)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreRunListener.testRunFinished(JUnitCoreRunListener.java:73)
[ERROR] at org.junit.runner.notification.RunNotifier$2.notifyListener(RunNotifier.java:95)
[ERROR] at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:61)
[ERROR] at org.junit.runner.notification.RunNotifier.fireTestRunFinished(RunNotifier.java:92)
[ERROR] at org.junit.runner.JUnitCore.run(JUnitCore.java:161)
[ERROR] at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
[ERROR] at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:113)
[ERROR] ... 6 more
[ERROR] Caused by: com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 51966
[ERROR] at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
[ERROR] at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
[ERROR] at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
[ERROR] at com.google.inject.internal.util.$StackTraceElements.forMember(StackTraceElements.java:53)
[ERROR] at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:716)
[ERROR] at com.google.inject.internal.Errors.formatSource(Errors.java:678)
[ERROR] at com.google.inject.internal.Errors.format(Errors.java:555)
[ERROR] at com.google.inject.CreationException.getMessage(CreationException.java:48)
[ERROR] at java.lang.Throwable.getLocalizedMessage(Throwable.java:391)
[ERROR] at java.lang.Throwable.toString(Throwable.java:480)
[ERROR] at java.lang.String.valueOf(String.java:2979)
[ERROR] at java.io.PrintWriter.println(PrintWriter.java:754)
[ERROR] at java.lang.Throwable$WrappedPrintWriter.println(Throwable.java:764)
[ERROR] at java.lang.Throwable.printStackTrace(Throwable.java:655)
[ERROR] at java.lang.Throwable.printStackTrace(Throwable.java:721)
[ERROR] at org.junit.runner.notification.Failure.getTrace(Failure.java:71)
[ERROR] at org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter.writeTraceToString(JUnit4StackTraceWriter.java:57)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:330)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:312)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.toString(ForkingRunListener.java:258)
[ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.testError(ForkingRunListener.java:132)
[ERROR] at org.apache.maven.surefire.junitcore.TestMethod.replay(TestMethod.java:118)
[ERROR] at org.apache.maven.surefire.junitcore.TestSet.replay(TestSet.java:87)
[ERROR] ... 14 more
[ERROR] Caused by: java.lang.ArrayIndexOutOfBoundsException: 51966
[ERROR] at com.google.inject.internal.asm.$ClassReader.readUTF8(Unknown Source)
[ERROR] at com.google.inject.internal.asm.$ClassReader.readClass(Unknown Source)
[ERROR] at com.google.inject.internal.asm.$ClassReader.accept(Unknown Source)
[ERROR] at com.google.inject.internal.asm.$ClassReader.accept(Unknown Source)
[ERROR] at com.google.inject.internal.util.$LineNumbers.<init>(LineNumbers.java:62)
[ERROR] at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:36)
[ERROR] at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:33)
[ERROR] at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
[ERROR] ... 36 more

从我读到的问题看来,lambdas 打破了 guice 错误处理,但人们仍然没有想出解决方案。如果有人知道这是关于什么的,请发表评论!

4

1 回答 1

12

当您的一个 guice 模块中的配置错误并且您使用的是 Java 8 lambdas 和 guice 3 时,会发生此不可读的异常。

我在这个问题上花了很多时间。每次,我都通过升级到guice 4 beta 解决了这个问题。它的特点之一是:

更好的 Java8 运行时兼容性

如果你使用 Maven:

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>4.0-beta5</version>
</dependency>

这个新版本会给你一个清晰的错误信息和一个适当的堆栈跟踪,让你找到问题。解决后,您可以切换回 guice 3.0 或继续使用 4.0-beta(据我所知,它已经稳定)。


编辑于 2016/07/13

请注意,guice 4.0 和 4.1 已经发布。所以你应该使用最新版本:

<dependency>
  <groupId>com.google.inject</groupId>
  <artifactId>guice</artifactId>
  <version>4.1.0</version>
</dependency>
于 2015-01-31T08:50:04.477 回答