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

NullPointerException in BeansXmlParser.merge

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • 3.0.5.Final
    • 3.0.4.Final
    • None
    • None
    • Hide

      Test class from /src/test/java:

      public class CoreEntityDaoTest {
      
          public static class DummyDao/* extends CoreEntityDao<DummyEntity, UUID>*/ {
              public DummyDao(EntityManager entityManager) {
              }
      
              public void findById(UUID uuid) {
              }
      
              public DummyEntity save(DummyEntity e) {
                  return e;
              }
          }
      
          @Table(name = "dummy")
          public static class DummyEntity {
      
          }
      
          @Inject
          private DummyDao dao;
      
          static Weld createWeld() {
              Weld weld = new Weld();
              // needed to allow visibility to the main beans, not just the test ones
              weld.property(Weld.ARCHIVE_ISOLATION_SYSTEM_PROPERTY, false);
              return weld;
          }
      
          @Rule
          public WeldInitiator weld = WeldInitiator.from(createWeld().addBeanClass(DummyDao.class))
                                                   .activate(RequestScoped.class)
                                                   .inject(this)
                                                   .build();
      
          @Test
          public void testSave() {
          }
      }
      

      This is a simplifed test class that should demonstrate the problem.
      Just run it as a JUnit test.

      Show
      Test class from /src/test/java : public class CoreEntityDaoTest { public static class DummyDao /* extends CoreEntityDao<DummyEntity, UUID>*/ { public DummyDao(EntityManager entityManager) { } public void findById(UUID uuid) { } public DummyEntity save(DummyEntity e) { return e; } } @Table(name = "dummy" ) public static class DummyEntity { } @Inject private DummyDao dao; static Weld createWeld() { Weld weld = new Weld(); // needed to allow visibility to the main beans, not just the test ones weld.property(Weld.ARCHIVE_ISOLATION_SYSTEM_PROPERTY, false ); return weld; } @Rule public WeldInitiator weld = WeldInitiator.from(createWeld().addBeanClass(DummyDao.class)) .activate(RequestScoped.class) .inject( this ) .build(); @Test public void testSave() { } } This is a simplifed test class that should demonstrate the problem. Just run it as a JUnit test.

      Running a test that's using weld-junit4 to initialize the CDI container triggers this exception:

      java.lang.NullPointerException
      	at org.jboss.weld.xml.BeansXmlParser.merge(BeansXmlParser.java:87)
      	at org.jboss.weld.xml.BeansXmlParser.mergeExisting(BeansXmlParser.java:122)
      	at org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive.merge(WeldBeanDeploymentArchive.java:142)
      	at org.jboss.weld.environment.se.Weld.createDeployment(Weld.java:978)
      	at org.jboss.weld.environment.se.Weld.initialize(Weld.java:773)
      	at org.jboss.weld.junit.AbstractWeldInitiator.initWeldContainer(AbstractWeldInitiator.java:495)
      	at org.jboss.weld.junit4.WeldInitiator.access$300(WeldInitiator.java:90)
      	at org.jboss.weld.junit4.WeldInitiator$1.evaluate(WeldInitiator.java:226)
      	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
      	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      	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)
      

      The test itself is incorrect (I was just trying to add the inner class DummyDao to the CDI context), but I don't think the NPE should be thrown anyway.
      To fix the test, marking the constructor of DummyDao with @Inject and removing the call .addBeanClass(DummyDao.class) is enough.

              manovotn Matěj Novotný
              andrei.ivanov@gmail.com Andrei Ivanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: