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();
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.
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.
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
, and spark-hive
(used in Project B) for some reason does not like when it has extra logging frameworks in the classpath, so we excluded it in sbt-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 from org.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 not Guice
fault.
Fix the ExclusionRule
and it all works with Guice 3 again.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With