reef-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sharath Malladi <shara...@microsoft.com.INVALID>
Subject Tang "ambiguous subplan" exception when using Lists
Date Mon, 18 Jun 2018 22:57:04 GMT
Hi,

If I have a class that has multiple injectors (one of which injects a list), then I get an
InjectionException about an "Ambiguous subplan".
As you can see from the exception below, it assumes that I attempted to bind to an empty list,
which I did not .. so there should be no ambiguity.

Is there a work around for this issue.

Thanks,
Sharath.

For example, here is the class with two injectors:


class TcpPortProvider {
  protected final List<String> list;
  protected final String s;

  @Inject
  TcpPortProvider(@Parameter(TcpPortList.class) final List<String> tcpPortList) {
    System.out.println("tcpPortList constructor");
    this.list = tcpPortList;
    this.s = "";
  }


  @Inject
  TcpPortProvider(@Parameter(TcpPortListString.class) final String s) {
    System.out.println("TcpPortListString constructor");
    this.s = s;
    this.list = null;
  }

  @NamedParameter
  static class TcpPortList implements Name<List<String>> {
  }

  @NamedParameter
  static class TcpPortListString implements Name<String> {
  }
}


And here is the code to instantiate using injection where I only supplied argument for the
injector that uses the string.


final JavaConfigurationBuilder cb = tang.newConfigurationBuilder();
cb.bindNamedParameter(TcpProvider.TcpPortListString.class, "this is a string");
tang.newInjector(cb.build()).getInstance(TcpPortProvider.class);



And here is the exception (note how it indicates that I also bound to an empty list):

org.apache.reef.tang.exceptions.InjectionException: Cannot inject org.apache.reef.tang.TcpPortProvider
Ambiguous subplan org.apache.reef.tang.TcpPortProvider
  new TcpPortProvider(String TcpPortListString = this is a string)
  new TcpPortProvider(list {
 } )
]

                at org.apache.reef.tang.implementation.java.InjectorImpl.injectFromPlan(InjectorImpl.java:600)
                at org.apache.reef.tang.implementation.java.InjectorImpl.getInstance(InjectorImpl.java:515)
                at org.apache.reef.tang.implementation.java.InjectorImpl.getInstance(InjectorImpl.java:533)
                at org.apache.reef.tang.TestTang.testTcpProvider(TestTang.java:452)
                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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
                at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
                at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
                at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
                at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
                at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:168)
                at org.junit.rules.RunRules.evaluate(RunRules.java:20)
                at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
                at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
                at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
                at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
                at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
                at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
                at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
                at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
                at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
                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)


Process finished with exit code -1



Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message