MyFaces Core
  1. MyFaces Core
  2. MYFACES-3035

PostConstruct method is called before properties are injected on Tomcat 7

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.5
    • Component/s: None
    • Labels:
      None
    • Environment:
      Tomcat 7.0.8, MyFaces 2.0.3

      Description

      Deploy attached project (use 'myfaces' profile only) under Tomcat 7 and open index.jsf. Inspect console output, Bean.init() should print injected list contents, however on Tomcat 7 it prints null. Tomcat 6 works as expected

      1. myfaces-3035.zip
        6 kB
        Nick Belaevski

        Activity

        Hide
        Jay Balunas added a comment -

        Weld had a similar issue - https://issues.jboss.org/browse/WELD-674 and solved it by implementing their own InstanceManager.

        Show
        Jay Balunas added a comment - Weld had a similar issue - https://issues.jboss.org/browse/WELD-674 and solved it by implementing their own InstanceManager.
        Hide
        Jay Balunas added a comment -

        BTW - Also confirmed with MyFaces 2.0.4.

        Show
        Jay Balunas added a comment - BTW - Also confirmed with MyFaces 2.0.4.
        Hide
        Gurkan Erdogdu added a comment -

        Tomcat7AnnotationLifecycleProvider calls Tomcat 7 Instancemanager for creation of MB instance and injection of annotations. Because Tomcat7 InstanceManager does not understand to inject @ManagedProperty this field is null. You can write your own instance manager.

        Show
        Gurkan Erdogdu added a comment - Tomcat7AnnotationLifecycleProvider calls Tomcat 7 Instancemanager for creation of MB instance and injection of annotations. Because Tomcat7 InstanceManager does not understand to inject @ManagedProperty this field is null. You can write your own instance manager.
        Hide
        Leonardo Uribe added a comment -

        I checke it and the problem is caused by the place used to call InstanceManager.newInstance. In tomcat 6 there is an interface called AnnotationProcessor:

        public interface AnnotationProcessor

        { public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException; public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException; public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException; }

        In tomcat 7.0 it was replaced by this interface:

        public interface InstanceManager

        { public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException; public Object newInstance(String fqcn, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException; public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, NamingException; public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException; }

        Now, the old processAnnotations() and postConstruct() code was merged in newInstance(Object o).

        The solution is just call this code from LifecycleProvider2.postConstruct, so managed properties are injected before postConstruct. In theory, the shouldn't be any problem, because we don't have a case were managed properties needs to be injected before processAnnotations code occur.

        Show
        Leonardo Uribe added a comment - I checke it and the problem is caused by the place used to call InstanceManager.newInstance. In tomcat 6 there is an interface called AnnotationProcessor: public interface AnnotationProcessor { public void postConstruct(Object instance) throws IllegalAccessException, InvocationTargetException; public void preDestroy(Object instance) throws IllegalAccessException, InvocationTargetException; public void processAnnotations(Object instance) throws IllegalAccessException, InvocationTargetException, NamingException; } In tomcat 7.0 it was replaced by this interface: public interface InstanceManager { public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException; public Object newInstance(String fqcn, ClassLoader classLoader) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException; public void newInstance(Object o) throws IllegalAccessException, InvocationTargetException, NamingException; public void destroyInstance(Object o) throws IllegalAccessException, InvocationTargetException; } Now, the old processAnnotations() and postConstruct() code was merged in newInstance(Object o). The solution is just call this code from LifecycleProvider2.postConstruct, so managed properties are injected before postConstruct. In theory, the shouldn't be any problem, because we don't have a case were managed properties needs to be injected before processAnnotations code occur.
        Hide
        Jay Balunas added a comment -

        The weld team did write their own instance manager. I believe the details are linked from the jira I commented on above. There code is up on github if you wanted to look.

        Show
        Jay Balunas added a comment - The weld team did write their own instance manager. I believe the details are linked from the jira I commented on above. There code is up on github if you wanted to look.

          People

          • Assignee:
            Leonardo Uribe
            Reporter:
            Nick Belaevski
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development