问题
Why Guice 3.0 throws this exception instead of a formatted message for wrong configurated components (@Inject is missing for example)?
Exception in thread "main" com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 16640
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.util.$StackTraceElements.forMember(StackTraceElements.java:53)
at com.google.inject.internal.Errors.formatInjectionPoint(Errors.java:716)
at com.google.inject.internal.Errors.formatSource(Errors.java:678)
at com.google.inject.internal.Errors.format(Errors.java:555)
at com.google.inject.ConfigurationException.getMessage(ConfigurationException.java:70)
at java.lang.Throwable.getLocalizedMessage(Throwable.java:391)
at java.lang.Throwable.toString(Throwable.java:480)
at java.lang.String.valueOf(String.java:2982)
at java.io.PrintStream.println(PrintStream.java:821)
at java.lang.Throwable$WrappedPrintStream.println(Throwable.java:748)
at java.lang.Throwable.printStackTrace(Throwable.java:655)
at java.lang.Throwable.printStackTrace(Throwable.java:643)
at java.lang.Throwable.printStackTrace(Throwable.java:634)
at hu.daniel.hari.exercises.cleanarchitecture.payrollcasestudy.adapters.primary.ui.impl.swing._2.SwingUIMain2.<init>(SwingUIMain2.java:40)
at hu.daniel.hari.exercises.cleanarchitecture.payrollcasestudy.adapters.primary.ui.impl.swing._2.SwingUIMain2.main(SwingUIMain2.java:17)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 16640
at com.google.inject.internal.asm.$ClassReader.readClass(Unknown Source)
at com.google.inject.internal.asm.$ClassReader.accept(Unknown Source)
at com.google.inject.internal.asm.$ClassReader.accept(Unknown Source)
at com.google.inject.internal.util.$LineNumbers.<init>(LineNumbers.java:62)
at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:36)
at com.google.inject.internal.util.$StackTraceElements$1.apply(StackTraceElements.java:33)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
... 17 more
My initating code is:
Injector injector = Guice.createInjector(new SwingUIModule(useCaseFactory));
injector.getInstance(MainFrameUI.class).show();
回答1:
I think the issue is with how Guice 3 and below handles lambda expressions. You might have to upgrade to Guice 4 to fix this as mentioned here.
回答2:
We have faced this issue and it turned out that it is not Guice 3 issue at all (in our case). Fact is, though, that due to poor Exception
handling in Guice 3 we got the same error message as the author.
TL/DR
The source of our problem was NoClassDefFoundError: Could not initialize class ...
exception that was thrown in a static block in one of our classes.
It turned out, that we had excluded too many classes during fat-jar building, and simply there were some classes missing. Unfortunately, with Guice 3, we received only $ComputationException: java.lang.ArrayIndexOutOfBoundsException: ...
message, to help us out.
My point is, that it might be, that Guice 3 is not the source of your problem.
Full version
We have a project (A) that we include as a dependency in project (B) that is running on Spark Cluster
Project A, was using
log4j 2
, andspark-hive
(used in Project B) for some reason does not like when it has extra logging frameworks in the classpath, so we excluded it insbt-assembly
:ExclusionRule(organization = "org.apache.logging.log4j"),
In project A, we have a class that has, lets say some code like this (java):
static { this.defaultMarker = MarkerManager.getMarker("abc") }
And
MarkerManager
is fromorg.apache.logging.log4j
, so this class is missing in fat-jar of project B.We run it on the cluster, where some class that is supposed to be
@injected
uses the class with static block.Boom!
$ComputationException: java.lang.ArrayIndexOutOfBoundsException
I decided to initialize all classes manually, without
Guice
only to find out that it was notGuice
fault.Fix the
ExclusionRule
and it all works with Guice 3 again.
来源:https://stackoverflow.com/questions/36376420/guice-3-0-arrayindexoutofboundsexception-on-startup