Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-627

fix wording regression for beans.xml alternative check introduced in 1.2

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.0 .Final
    • 1.2.Final
    • Concepts
    • None

      My scenario is the following:
      I have an @Alternative MockMailService class which should only be used during testing to not send out 5k mails to customers and employees when running the unit and integration test suite.

      @Alternative
      @ApplicationScoped
      @Exclude(ifProjectStage=Production.class)
      public class MockMailService implements MailService {...}
      

      Of course I only need to activate it in beans.xml:

      <beans>
        <alternatives>
          <class&gt;org.acme.MockMailService</class&gt;
        </alternatives>
      </beans>
      

      This is perfectly fine in CDI 1.0 but might be interpreted as not be allowed in the CDI 1.2 wording paragraph 5.1.1.2. "Declaring selected alternatives for a bean archive".

      Please note that we introduced a check in CDI 1.0 purely to help the customer eagerly detect possible wrong configuration. E.g. if he simply has a typo in the classname. It was not intended to restrict useful use cases!

      What the intention was: all is fine IF one of

      • There exists a class T with the given name
      • That class T (or a contained producer field or producer method) is annotated with @Alternative
      • There is a Bean<T> with isAlternative() == true

              struberg Mark Struberg (Inactive)
              struberg Mark Struberg (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: