glassfish
  1. glassfish
  2. GLASSFISH-19626

NullPointer Exception using @Inject in glassfish build 72

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 4.0_b70
    • Fix Version/s: 4.0
    • Component/s: cdi
    • Labels:
      None
    • Environment:

      glassfish-4.0-b72 , primefaces 3.4 and JSF 2.2 Mojarra in glassfish

      Description

      I am getting Null pointer exception when I use @Inject annotation to inject a service class defined in jar into my fa?ade defined war .
      I am using glassfish-4.0-b72 , primefaces 3.4 and JSF 2.2 defined in glassfish. Mojarra loads without any issues and so does primefaces.
      When I use @Inject the injected bean does not get instantiated . Please let me know if I am missing something
      I have beans.xml included in my .war and .jar as well.

        Activity

        Hide
        Hong Zhang added a comment - - edited

        Assign to CDI team for evaluation.

        Show
        Hong Zhang added a comment - - edited Assign to CDI team for evaluation.
        Hide
        tlcksnyder added a comment -

        Do you have a test case you can share?

        Show
        tlcksnyder added a comment - Do you have a test case you can share?
        Hide
        niveditadixitp added a comment -

        No test case. But can explain in more detail

        web layer in web project
        include the service project in web project as deployment assembly dependency
        1) ManagedBean has reference to the facade class
        2) Facade class injects the service layer class defined in service.jar as follows
        @Inject
        private VendorService vendorService ;
        3) included beans.xml in WEB-INF of the web project having content <beans/>

        Service and persistent layer classes are in java project
        4) VendorService is inerface and VendorServiceImpl is the implementation
        5) included beans.xml in META-INF of the javaproject having content <beans/>

        Show
        niveditadixitp added a comment - No test case. But can explain in more detail web layer in web project include the service project in web project as deployment assembly dependency 1) ManagedBean has reference to the facade class 2) Facade class injects the service layer class defined in service.jar as follows @Inject private VendorService vendorService ; 3) included beans.xml in WEB-INF of the web project having content <beans/> Service and persistent layer classes are in java project 4) VendorService is inerface and VendorServiceImpl is the implementation 5) included beans.xml in META-INF of the javaproject having content <beans/>
        Hide
        marina vatkina added a comment -

        I'm wondering is it's the same problem as I reported in http://java.net/jira/browse/GLASSFISH-19581 (which I'm seeing more often in the hudson runs recently)

        Show
        marina vatkina added a comment - I'm wondering is it's the same problem as I reported in http://java.net/jira/browse/GLASSFISH-19581 (which I'm seeing more often in the hudson runs recently)
        Hide
        jwells added a comment -

        I'm going to need more information (or a test case). For example, I need to see the code for the ManagedBean and the FacadeClass and I'd like to see the code for VendorService and VendorServiceImpl.

        Also, it'd be nice to get service.jar and whatever.war you have to see if I can reproduce this.

        Show
        jwells added a comment - I'm going to need more information (or a test case). For example, I need to see the code for the ManagedBean and the FacadeClass and I'd like to see the code for VendorService and VendorServiceImpl. Also, it'd be nice to get service.jar and whatever.war you have to see if I can reproduce this.
        Hide
        tlcksnyder added a comment -

        This bug will get moved to a future release without a test case.

        Show
        tlcksnyder added a comment - This bug will get moved to a future release without a test case.
        Hide
        niveditadixitp added a comment -

        Please find below the code managed bean and the service class in services.jar

        /**

        • */
          package net.java.adoptjsr.fcms.web.beans;

        import java.io.Serializable;
        import java.util.List;

        import javax.annotation.PostConstruct;
        import javax.faces.bean.ManagedProperty;
        import javax.faces.bean.RequestScoped;
        import javax.inject.Named;

        import net.java.adoptjsr.fcms.facade.VendorFacade;
        import net.java.adoptjsr.fcms.facade.impl.VendorFacadeImpl;
        import net.java.adoptjsr.fcms.model.TrustedVendor;
        import net.java.adoptjsr.fcms.model.Vendor;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        /**

        • @author Nivedita_Dixit
          *
          */
          @Named(value="vendorBean")
          @RequestScoped
          public class VendorMaintainBean implements Serializable {

        /**

        • */
          private static final long serialVersionUID = -6731561541756443536L;

        /**

        • Logger
          */
          Logger log = LoggerFactory.getLogger(VendorMaintainBean.class);

        @ManagedProperty(value="#

        {param.page}

        ")
        private String page;

        private Vendor vendor;

        private List<Vendor> vendors;

        private VendorFacade vendorFacade = new VendorFacadeImpl();

        /**

        • @return the vendors
          */
          public List<Vendor> getVendors() { return vendors; }

        /**

        • @param vendors the vendors to set
          */
          public void setVendors(List<Vendor> vendors) { this.vendors = vendors; }

        /**

        • @return the vendorFacade
          */
          public VendorFacade getVendorFacade() { return vendorFacade; }

        /**

        • @param vendorFacade the vendorFacade to set
          */
          public void setVendorFacade(VendorFacade vendorFacade) { this.vendorFacade = new VendorFacadeImpl(); }

        /**

        • @return the page
          */
          public String getPage() { return page; }

        /**

        • @param page the page to set
          */
          public void setPage(String page) { this.page = page; }

        /**

        • @return the vendor
          */
          public Vendor getVendor() { return vendor; }

        /**

        • @param vendor the vendor to set
          */
          public void setVendor(Vendor vendor) { this.vendor = vendor; }

        /**

        • Default Constructor
          */
          public VendorMaintainBean() { super(); vendor = new TrustedVendor(); }

        @PostConstruct
        public void init()

        { System.out.println(page); page="vendor/search"; }

        /**

        • @return
          */
          public String find() { System.out.println( "in find"); return null; }

        /**

        • @return
          */
          public String save() { vendorFacade.saveVendor(vendor); vendors = vendorFacade.findVendors(vendor); return null; }

        /**

        • @return
          */
          public String delete() { return null; }


          /**
          *
          * @return
          */
          public String clear(){ vendor.setVendorName(null); return null; }

          /**
          *
          * @return
          */
          public String reset(){ return null; }

        }

        package net.java.adoptjsr.fcms.facade.impl;

        import java.util.List;

        import javax.inject.Inject;

        import net.java.adoptjsr.fcms.facade.VendorFacade;
        import net.java.adoptjsr.fcms.model.Vendor;
        import net.java.adoptjsr.fcms.service.VendorService;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        /**

        • @author Nivedita_Dixit
        • */
          public class VendorFacadeImpl implements VendorFacade {

        /**

        • Logger
          */
          Logger log = LoggerFactory.getLogger(VendorFacadeImpl.class);

        @Inject
        private VendorService vendorService ;

        @Override
        public Vendor saveVendor(Vendor vendor)

        { vendor = vendorService.saveVendor(vendor); return vendor; }

        @Override
        public Vendor findVendor(Vendor vendor)

        { return null; }

        public List<Vendor> findVendors(Vendor vendor)

        { return vendorService.findVendors(vendor); }

        }

        /**

        • */
          package net.java.adoptjsr.fcms.service.impl;

        import java.util.List;

        import javax.enterprise.inject.Default;

        import net.java.adoptjsr.fcms.dao.VendorDao;
        import net.java.adoptjsr.fcms.dao.impl.VendorDaoImpl;
        import net.java.adoptjsr.fcms.model.Vendor;
        import net.java.adoptjsr.fcms.service.VendorService;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        /**

        • @author Nivedita_Dixit
        • */
          @Default
          public class VendorServiceImpl implements VendorService {

        /**

        • Logger
          */
          Logger log = LoggerFactory.getLogger(VendorServiceImpl.class);

        private VendorDao vendorDao = new VendorDaoImpl();

        /**

        • */
          public VendorServiceImpl()

          { super(); }

        /**

        • @return the vendorDao
          */
          public VendorDao getVendorDao() { return vendorDao; }

        /**

        • @param vendorDao the vendorDao to set
          */
          public void setVendorDao(VendorDao vendorDao) { this.vendorDao = vendorDao; }

        /**

        • */
          public Vendor saveVendor(Vendor vendor)

          { vendor = vendorDao.saveVendor(vendor); return vendor; }

        /**

        • */
          public void removeVendor(Vendor vendor)

          { vendorDao.removeVendor(vendor); }

        /**

        • */
          public List<Vendor> findVendors(Vendor vendor)

          { return vendorDao.findVendors(vendor); }

        }

        Show
        niveditadixitp added a comment - Please find below the code managed bean and the service class in services.jar /** */ package net.java.adoptjsr.fcms.web.beans; import java.io.Serializable; import java.util.List; import javax.annotation.PostConstruct; import javax.faces.bean.ManagedProperty; import javax.faces.bean.RequestScoped; import javax.inject.Named; import net.java.adoptjsr.fcms.facade.VendorFacade; import net.java.adoptjsr.fcms.facade.impl.VendorFacadeImpl; import net.java.adoptjsr.fcms.model.TrustedVendor; import net.java.adoptjsr.fcms.model.Vendor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @author Nivedita_Dixit * */ @Named(value="vendorBean") @RequestScoped public class VendorMaintainBean implements Serializable { /** */ private static final long serialVersionUID = -6731561541756443536L; /** Logger */ Logger log = LoggerFactory.getLogger(VendorMaintainBean.class); @ManagedProperty(value="# {param.page} ") private String page; private Vendor vendor; private List<Vendor> vendors; private VendorFacade vendorFacade = new VendorFacadeImpl(); /** @return the vendors */ public List<Vendor> getVendors() { return vendors; } /** @param vendors the vendors to set */ public void setVendors(List<Vendor> vendors) { this.vendors = vendors; } /** @return the vendorFacade */ public VendorFacade getVendorFacade() { return vendorFacade; } /** @param vendorFacade the vendorFacade to set */ public void setVendorFacade(VendorFacade vendorFacade) { this.vendorFacade = new VendorFacadeImpl(); } /** @return the page */ public String getPage() { return page; } /** @param page the page to set */ public void setPage(String page) { this.page = page; } /** @return the vendor */ public Vendor getVendor() { return vendor; } /** @param vendor the vendor to set */ public void setVendor(Vendor vendor) { this.vendor = vendor; } /** Default Constructor */ public VendorMaintainBean() { super(); vendor = new TrustedVendor(); } @PostConstruct public void init() { System.out.println(page); page="vendor/search"; } /** @return */ public String find() { System.out.println( "in find"); return null; } /** @return */ public String save() { vendorFacade.saveVendor(vendor); vendors = vendorFacade.findVendors(vendor); return null; } /** @return */ public String delete() { return null; } /** * * @return */ public String clear(){ vendor.setVendorName(null); return null; } /** * * @return */ public String reset(){ return null; } } package net.java.adoptjsr.fcms.facade.impl; import java.util.List; import javax.inject.Inject; import net.java.adoptjsr.fcms.facade.VendorFacade; import net.java.adoptjsr.fcms.model.Vendor; import net.java.adoptjsr.fcms.service.VendorService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @author Nivedita_Dixit */ public class VendorFacadeImpl implements VendorFacade { /** Logger */ Logger log = LoggerFactory.getLogger(VendorFacadeImpl.class); @Inject private VendorService vendorService ; @Override public Vendor saveVendor(Vendor vendor) { vendor = vendorService.saveVendor(vendor); return vendor; } @Override public Vendor findVendor(Vendor vendor) { return null; } public List<Vendor> findVendors(Vendor vendor) { return vendorService.findVendors(vendor); } } /** */ package net.java.adoptjsr.fcms.service.impl; import java.util.List; import javax.enterprise.inject.Default; import net.java.adoptjsr.fcms.dao.VendorDao; import net.java.adoptjsr.fcms.dao.impl.VendorDaoImpl; import net.java.adoptjsr.fcms.model.Vendor; import net.java.adoptjsr.fcms.service.VendorService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** @author Nivedita_Dixit */ @Default public class VendorServiceImpl implements VendorService { /** Logger */ Logger log = LoggerFactory.getLogger(VendorServiceImpl.class); private VendorDao vendorDao = new VendorDaoImpl(); /** */ public VendorServiceImpl() { super(); } /** @return the vendorDao */ public VendorDao getVendorDao() { return vendorDao; } /** @param vendorDao the vendorDao to set */ public void setVendorDao(VendorDao vendorDao) { this.vendorDao = vendorDao; } /** */ public Vendor saveVendor(Vendor vendor) { vendor = vendorDao.saveVendor(vendor); return vendor; } /** */ public void removeVendor(Vendor vendor) { vendorDao.removeVendor(vendor); } /** */ public List<Vendor> findVendors(Vendor vendor) { return vendorDao.findVendors(vendor); } }

          People

          • Assignee:
            jwells
            Reporter:
            niveditadixitp
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: