Uploaded image for project: 'OpenWebBeans'
  1. OpenWebBeans
  2. OWB-742

@Alternative is ignored when using the Provider interface.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.1.8
    • None
    • None

    Description

      I have a very simple setup where I have classes Foo1 and Foo2 that implement the Foo interface

      public interface Foo {
      }
      @Default
      public class Foo1 implements Foo {

      }
      @Alternative
      public class Foo2 implements Foo {

      }

      Then a class that gets 2 Foos injected

      public class Main {

      @Inject
      Foo fooA;

      @Inject
      Provider<Foo> fooB;

      @PostConstruct
      public void init()

      { System.err.println("FooA:" + fooA); System.err.println("FooB:" + fooB.get()); }

      }

      If my beans.xml file is empty, then I get 2 instances of Foo1 injected into the class, as expected.

      However, if I add

      <alternatives>
      <class>Foo2</class>
      </alternatives>

      to my beans.xml, then I get an error when I run the application.

      """
      INFO: All injection points were validated successfully.
      Dec 26, 2012 9:11:29 PM org.apache.webbeans.lifecycle.AbstractLifeCycle startApplication
      INFO: OpenWebBeans Container has started, it took [359] ms.
      FooA:Foo2@152c4d9
      Dec 26, 2012 9:11:29 PM org.apache.webbeans.component.AbstractInjectionTargetBean postConstructDefault
      SEVERE: An error occurred while executing [@PostConstruct.]
      javax.enterprise.inject.AmbiguousResolutionException: There is more than one api type with : Foo with qualifiers : Qualifiers: [@javax.enterprise.inject.Default()]
      found beans:
      Foo1, Name:null, WebBeans Type:MANAGED, API Types:[Foo,Foo1,java.lang.Object], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
      Foo2, Name:null, WebBeans Type:MANAGED, API Types:[Foo,java.lang.Object,Foo2], Qualifiers:[javax.enterprise.inject.Any,javax.enterprise.inject.Default]
      at org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionExceptionForBeans(InjectionExceptionUtils.java:121)
      at org.apache.webbeans.util.InjectionExceptionUtils.throwAmbiguousResolutionException(InjectionExceptionUtils.java:111)
      at org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:80)
      at org.apache.webbeans.inject.instance.InstanceImpl.get(InstanceImpl.java:110)
      at Main.init(Main.java:23)
      """

      This exception happens when I call Provider.get(). I assumed that the Provider interface would respect the Alternative Qualifiers, but that does not seem to be the case.

      Attachments

        Issue Links

          Activity

            People

              arne Arne Limburg
              molson1992 Mike Olson
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: