Why is a lambda expression breaking guice error handling when i try to start jetty?

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

I face the following problem where i try to start jetty, i get the following exeption:

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 

From what i've read the problem seems that lambdas break guice error handling, but still people haven't come up with a solution. If someone knows what this is about please post comment!

回答1:

This unreadable exception occurs when you have a bad configuration in one of your guice modules and you are using Java 8 lambdas and guice 3.

I have spent a lot of time with this issue. Each time, I solved the problem by upgrading to guice 4 beta. One of its features is:

Better Java8 runtime compatibility

If you use maven:

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

This new version will give you a clear error message and a proper stacktrace that will let you find the problem. When you have solved it, you can switch back to guice 3.0 or continue to using the 4.0-beta (which is - from what I've seen - already stable).


Edited the 2016/07/13

Note that guice 4.0 and 4.1 have been released. So you should use the latest release:

<dependency>   <groupId>com.google.inject</groupId>   <artifactId>guice</artifactId>   <version>4.1.0</version> </dependency> 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!