Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-974

@Alternative @Specializes does not work

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Done
    • Affects Version/s: 1.1.2.Final
    • Fix Version/s: 1.1.4.Final
    • Component/s: None
    • Labels:
      None

      Description

      See pull request with testcase.

      @ApplicationScoped
      @Named("namedFoo") // doesn't matter if it's @Named or not
      public class NamedFoo
      {
       
      }
       
      @Alternative @Specializes
      public class SpecializesNamedFoo extends NamedFoo
      {
       
      }
       
       
         @Test
         public void testSpecializationWithAlternative()
         {
            Assert.assertEquals(NamedFoo.class, beanManager.resolve(beanManager.getBeans(NamedFoo.class)).getBeanClass()); // FAILS WITH NPE!
         }
      

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            Here's the pull request with the failing testcase:
            https://github.com/weld/core/pull/134

            Show
            ge0ffrey Geoffrey De Smet added a comment - Here's the pull request with the failing testcase: https://github.com/weld/core/pull/134
            Hide
            jensaug Jens Augustsson added a comment -

            Geoffrey,

            First, I assume you'd like to resolve your SpecializesNamedFoo, not NamedFoo?

            	@Test
            	public void testSpecializationWithAlternative() {
            		Assert.assertEquals(SpecializesNamedFoo.class,	beanManager.resolve(beanManager.getBeans(NamedFoo.class)).getBeanClass());
            	}
            

            Second, I believe the behavior is expected, because according to the spec, alternatives should be by default disabled unless you enable them in beans.xml. So if I modify your test case to reflect this, it passes the test:

            	@Deployment
            	public static Archive<?> deploy() {
            	      return ShrinkWrap.create(BeanArchive.class)
            	      	 .alternate(SpecializesNamedFoo.class)
            	         .addPackage(SpecializationTest.class.getPackage());		
            	}
            

            Or?

            br,
            Jens

            Show
            jensaug Jens Augustsson added a comment - Geoffrey, First, I assume you'd like to resolve your SpecializesNamedFoo, not NamedFoo? @Test public void testSpecializationWithAlternative() { Assert.assertEquals(SpecializesNamedFoo.class, beanManager.resolve(beanManager.getBeans(NamedFoo.class)).getBeanClass()); } Second, I believe the behavior is expected, because according to the spec, alternatives should be by default disabled unless you enable them in beans.xml. So if I modify your test case to reflect this, it passes the test: @Deployment public static Archive<?> deploy() { return ShrinkWrap.create(BeanArchive.class) .alternate(SpecializesNamedFoo.class) .addPackage(SpecializationTest.class.getPackage()); } Or? br, Jens
            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            Hi Jens,

            The alternative is deliberately not activated: the testcase should expect to get a NamedFoo.class instead, not a SpecializesNamedFoo.class.
            The bug is that the presence of SpecalizesNamedFoo creates an NPE on

            beanManager.resolve(beanManager.getBeans(NamedFoo.class))
            

            Show
            ge0ffrey Geoffrey De Smet added a comment - Hi Jens, The alternative is deliberately not activated: the testcase should expect to get a NamedFoo.class instead, not a SpecializesNamedFoo.class. The bug is that the presence of SpecalizesNamedFoo creates an NPE on beanManager.resolve(beanManager.getBeans(NamedFoo.class))
            Hide
            jensaug Jens Augustsson added a comment -

            ...ah, point taken!

            Show
            jensaug Jens Augustsson added a comment - ...ah, point taken!
            Hide
            ge0ffrey Geoffrey De Smet added a comment -

            This is fixed in 1.1.4.Final, probably by Ales's work.
            I 'll poke him to add the regression test to weld's master if he hasn't a similar one already.

            Show
            ge0ffrey Geoffrey De Smet added a comment - This is fixed in 1.1.4.Final, probably by Ales's work. I 'll poke him to add the regression test to weld's master if he hasn't a similar one already.

              People

              • Assignee:
                alesj Ales Justin
                Reporter:
                ge0ffrey Geoffrey De Smet
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development