3 Replies Latest reply on May 15, 2015 11:31 AM by Marek Novotny

    java.lang.StackOverflowError Evaluate Expression in Constructor

    omid pourhadi Apprentice

      Hi,

       

      I created a query parameter in my page.xml file when I try to evaluate it by Seam Expression I get stackoverflow here is my code

       

      public class ProjectFilter{
      
           public ProjectFilter(){
                Expressions.instance().createValueExpression("#{projectFilter.projectFilterParameters.program1Id}").getValue() // cause stackoverflow
                Parameters.instance().convertMultiValueRequestParameter(Parameters.instance().getRequestParameters(), "program1Id", Long.class); //works
           }
      
           public List<Project> getProjectList(){
                Expressions.instance().createValueExpression("#{projectFilter.projectFilterParameters.program1Id}").getValue() // works again
           }
      
           
      
      }
      

       

      project.page.xml

       

      <param name="program1Id" value="#{projectFilter.projectFilterParameters.program1Id}"/>
      

       

      I can't understand the difference why this is happening ?

        • 1. Re: java.lang.StackOverflowError Evaluate Expression in Constructor
          Marek Novotny Master

          Please provide more details like Seam annotations on ProjectFilter class or show your error stack trace.

          • 2. Re: java.lang.StackOverflowError Evaluate Expression in Constructor
            omid pourhadi Apprentice

            I looked at Seam EntityQuery and I think this is by design even EntityQuery evaluates Expressions after you call getResultList() method so it is impossible to evaluate expressions in Constructor.

             

            is this correct ?

             

            @Name("projectFilter")
            @Scope(Scope.Conversation)
            public class ProjectFilter implements Serializable{
            
            private ProjectFilterParameters projectFilterParameters = new ProjectFilterParameters();
            
            public ProjectFilterParameters getProjectFilterParameters(){
               return projectFilterParameters;
            }
            
            public ProjectFilter(){
               System.out.println(Expressions.instance().createValueExpression("#{projectFilter.projectFilterParameters.program1Id}").getValue()) // cause stackoverflow
            }
            
            }
            

             

            public class ProjectFilterParameters implements Serializable {
               private Long program1Id;
            
               public void setProgram1Id(long program1Id){
                 this.program1Id = program1Id;
            }
            
            public long getProgram1Id(){
            return program1Id;
            }
            
            }
            

             

            <param name="program1Id" value="#{projectFilter.projectFilterParameters.program1Id}"/>
            

             

             

            <h:form>
            <h:inputText value="#{projectFilter.projectFilterParameters.program1Id}" id="program1Id" />
            <h:commandButton value="Search" action="/projectFilter.xhtml" />
            </h:form>
            
            • 3. Re: java.lang.StackOverflowError Evaluate Expression in Constructor
              Marek Novotny Master

              yep, I didn't realized that you are cycling in the same constructor like you are evaluating in the expression.

               

              the #{projectFilter} will try to find existing instance of ProjectFilter and if that is not found it will call its constructor so that's why you get stackoverflow.