we are using dagger 2.0 to bind modules in our app. Though we use setting tests with guice 3.0 and up to now all worked properly until I added new method binding in used class and as a parameter I use :
Optional<Set<DataGroup>> dataGroups
which in my class in code looks like :
@Inject
public void setDataGroups(@Named(DATA_GROUPS) Optional<Set<DataGroup>>
dataGroups) {
this.dataGroups = dataGroups;
}
in my test module which uses guice I bind these data groups this way:
Optional<Set<DataGroup>> dataGroups = Optional.of((new HashSet<DataGroup>());
bind(new TypeLiteral<Optional<Set<DataGroup>>>() {
}).toInstance(dataGroups);
and it does not work. By running a test I gets :
com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException
what is weird if I implement my setDataGroups() method in code by providing List interface (of course with changing declaration for dataGroups field) instead all works fine :
@Inject
public void setDataGroups(@Named(DATA_GROUPS) Optional<List<DataGroup>>
dataGroups) {
this.dataGroups = dataGroups;
}
and binding in test module in guice :
Optional<List<DataGroup>> dataGroups = Optional.of(new ArrayList<DataGroup>());
bind(new TypeLiteral<Optional<List<DataGroup>>>() {
}).toInstance(dataGroups);
So I wonder if there is something special between binding Set and List because I can not find any clue why setting Set interface does not work in guice and breaks test module
I tried to use guice 4.0 as I read about similiar problems but they touch rather lambdas than binding Set interface with HashSet instance.
Thanks in advance.
The whole exception below :
com.google.inject.internal.util.$ComputationException: java.lang.ArrayIndexOutOfBoundsException: 75777
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.CreationException.getMessage(CreationException.java:48)
at java.lang.Throwable.getLocalizedMessage(Throwable.java:391)
at java.lang.Throwable.toString(Throwable.java:480)
at java.lang.Throwable.<init>(Throwable.java:311)
at java.lang.Exception.<init>(Exception.java:102)
at java.lang.RuntimeException.<init>(RuntimeException.java:96)
at org.jboss.arquillian.core.spi.InvocationException.<init>(InvocationException.java:33)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:107)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:88)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:145)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:116)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:201)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:426)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:54)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:218)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:166)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 75777
at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
at com.google.inject.internal.asm.$ClassReader.<init>(Unknown Source)
at com.google.inject.internal.asm.$ClassReader.<init>(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)
... 44 more
Test ignored.
Disconnected from the target VM, address: '127.0.0.1:54693', transport: 'socket'
Process finished with exit code -1