3 Replies Latest reply on Jan 3, 2008 3:00 PM by Pete Muir

    IllegalArgumentException: Stack must not be null

    Levent Aksu Newbie

      Hello,
      I am trying to cook my first component test:

      public class CategoryInteraction extends SeamTest {
      
       @Test
       public void testMest() throws Exception {
      
       new ComponentTest(){
      
       @Override
       protected void testComponents() throws Exception {
       String result=(String)invokeMethod("#{categoryAction.nevv('E')}");
       assert result.equals("categoryDefine");
       }
       }.run();
       }
      }

      I get this weird stack trace:
      java.lang.IllegalArgumentException: Stack must not be null
       at org.jboss.seam.core.ConversationEntry.<init>(ConversationEntry.java:39)
       at org.jboss.seam.core.ConversationEntries.createConversationEntry(ConversationEntries.java:53)
       at org.jboss.seam.core.Manager.createConversationEntry(Manager.java:537)
       at org.jboss.seam.core.Manager.beginConversation(Manager.java:558)
       at org.jboss.seam.core.ConversationInterceptor.beginConversation(ConversationInterceptor.java:229)
       at org.jboss.seam.core.ConversationInterceptor.beginConversationIfNecessary(ConversationInterceptor.java:166)
       at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:57)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
       at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
       at datassist.payroll.action.CategoryAction_$$_javassist_0.nevv(CategoryAction_$$_javassist_0.java)
       at datassist.payroll.test.CategoryInteraction$1.testComponents(CategoryInteraction.java:22)
       at org.jboss.seam.mock.BaseSeamTest$ComponentTest.run(BaseSeamTest.java:167)
       at datassist.payroll.test.CategoryInteraction.testMest(CategoryInteraction.java:31)
      ... Removed 22 stack frames


      I went to debug it to some level: It looks like Manager object is not initialized properly or something.

      I am using Seam 2.0.1.CR1

        • 2. Re: IllegalArgumentException: Stack must not be null
          Levent Aksu Newbie

           

          /*
           * CategoryActionBean.java
           *
           * Created on July 11, 2007, 3:45 PM
           *
           * To change this template, choose Tools | Template Manager
           * and open the template in the editor.
           */
          
          package datassist.payroll.action;
          
          
          import datassist.payroll.entity.ChildValuesPresentException;
          import datassist.payroll.entity.NotFocusedException;
          import datassist.payroll.entity.value.Value;
          import java.util.Date;
          import java.util.List;
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Out;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Begin;
          import org.jboss.seam.annotations.End;
          import org.jboss.seam.annotations.Scope;
          import datassist.payroll.entity.Category;
          import datassist.payroll.entity.variable.Variable;
          import java.io.Serializable;
          import org.hibernate.Session;
          import org.jboss.seam.annotations.FlushModeType;
          import org.jboss.seam.annotations.Logger;
          import org.jboss.seam.core.Events;
          import org.jboss.seam.faces.FacesMessages;
          import org.jboss.seam.log.Log;
          
          
          @Name("categoryAction")
          @Scope(ScopeType.CONVERSATION)
          public class CategoryAction implements Serializable {
          
           public CategoryAction() {
          
           }
           private static final String updateState="update";
           private static final String correctState="correct";
          
           @In(create=true)
           private Session hibernateSession;
          
           @In(value="facesMessages")
           FacesMessages messages;
          
           @Out @In(required=false)
           Category category;
          
           public String state;
           private Date lastEffectiveDate=new Date();
          
           @Begin(flushMode=FlushModeType.MANUAL)
           public String nevv(String categoryType){
           category = new Category();
           logger.debug("nevv:categoryType ="+categoryType);
           category.setType(categoryType);
           category.edit();
           category.sortValues();
           return "categoryDefine";
           }
          
           @Begin(flushMode=FlushModeType.MANUAL)
           public String nevvBelow(CategoryNode selection) {
           category = new Category();
           Category parent = selection.value;
           logger.debug("nevvBelow:Category below=" + parent);
           hibernateSession.refresh(parent);
           category.setType(parent.getType());
           category.setParentCategory(parent);
           category.edit();
           logger.debug("nevvBelow Category below another category is created");
           return "categoryDefine";
           }
          
           @Begin(flushMode=FlushModeType.MANUAL)
           public String correct(CategoryNode selection){
           logger.trace("CategoryAction edit selection:"+selection.getValue());
           category=selection.getValue();
           hibernateSession.refresh(category);
           category.edit();
           state=correctState;
           System.out.println("categoryaction correct state:"+state);
           return "categoryEdit";
           }
          
           @Begin(flushMode=FlushModeType.MANUAL)
           public String update(CategoryNode selection){
           logger.trace("CategoryAction edit selection:"+selection.getValue());
           category=selection.getValue();
           hibernateSession.refresh(category);
           category.edit();
           category.sortValues();
           state=updateState;
           System.out.println("categoryaction update state:"+state);
           category.setOldValues(category.getCopyOfValues(category.getCurrentValues()));
           return "categoryEdit";
           }
           //@Begin(flushMode=FlushModeType.MANUAL)
           public String show(CategoryNode selection){
           logger.trace("CategoryAction show selection:"+selection.getValue());
           category=selection.getValue();
           hibernateSession.refresh(category);
           category.show();
           return "categoryEdit";
           }
           @Begin(flushMode=FlushModeType.MANUAL)
           public String define(CategoryNode selection){
           logger.trace("CategoryAction define selection:"+selection);
           category=selection.getValue();
           hibernateSession.refresh(category);
           category.edit();
           return "categoryDefine";
           }
          
          
           @End
           public String save(){
           System.out.println("categoryAction save method state:"+state);
           logger.debug("About to saveOrUpdate category:"+category);
           category.stripUnusedValues();
           if (isUpdateState())
           category.arrangeValues(lastEffectiveDate);
           hibernateSession.saveOrUpdate(category);
           Category parent=category.getParentCategory();
           if (parent!=null && !parent.getChildCategories().contains(category))
           parent.addToChildCategories(category);
          
           hibernateSession.flush();
           logger.debug("category saved:"+category);
           messages.add("Category was saved successfully");
           Events.instance().raiseEvent("categoryTreeRefresh");
           category.blur();
           return "categoryTree";
           }
          
           @End
           public String cancel(){
           Events.instance().raiseEvent("categoryTreeClearSelection");
           hibernateSession.evict(category);
           hibernateSession.flush();
           Events.instance().raiseEvent("categoryTreeRefresh");
           category.blur();
           return "categoryTree";
           }
          
           public void addVariable(){
           logger.trace("Adding variable. variableName:"+getVariableName()+" variableType:"+getVariableType());
           try {
           List<Variable> varList=category.getAllVariables();
           if (varList!=null){
           for (Variable var:varList){
           if (var.getName().equals(getVariableName())){
           messages.add("Variable name was already used");
           return;
           }
           }
           }
           Variable variable =(Variable)(Class.forName("datassist.payroll.entity.variable."+getVariableType()).newInstance());
           variable.setName(getVariableName());
           variable.setLabel(getVariableLabel());
           variable.setDescription(getVariableDescription());
           category.addToVariables(variable);
           System.out.println("Variable is created : "+variable);
           category.resetVariables();
           } catch (ClassNotFoundException ex) {
           ex.printStackTrace();
           } catch (IllegalAccessException ex) {
           ex.printStackTrace();
           } catch (InstantiationException ex) {
           ex.printStackTrace();
           } catch (NotFocusedException ex){
           ex.printStackTrace();
           }
           }
          
           public void removeVariable(Variable variableDelete) throws ChildValuesPresentException,NotFocusedException{
           System.out.println("CategoryAction.removeVariable started");
           if (category.checkValuesExistsForOtherCategories(variableDelete)){
           messages.add("Used category cannot be deleted");
           }else{
          
          // TODO: reWrite
           Value valueDelete = variableDelete.getCategory().getCurrentValue(variableDelete);
           category.getValues().remove(valueDelete);
           category.getVariables().remove(variableDelete);
           category.getAllVariables().remove(variableDelete);
           category.resetVariables();
           category.getVariables().remove(variableDelete);
           hibernateSession.delete(variableDelete);
           hibernateSession.flush();
           hibernateSession.refresh(category);
           category.focus();
          
           }
           System.out.println("CategoryAction.removeVariable finished");
           }
          
           public void showChanges(){
           logger.trace("Showing changes");
           }
          
          
           @Logger
           Log logger;
          
           private String variableName;
           private String variableType;
           private String variableLabel;
           private String variableDescription;
          
           public String getVariableName() {
           logger.trace("unitCategoryAction.getVariableName is called");
           return variableName;
           }
          
           public void setVariableName(String variableName) {
           logger.trace("unitCategoryAction.setVariableName is called");
           this.variableName = variableName;
           }
          
           public String getVariableType() {
           return variableType;
           }
          
           public void setVariableType(String variableType) {
           this.variableType = variableType;
           }
          
           public String getVariableLabel() {
           return variableLabel;
           }
          
           public void setVariableLabel(String variableLabel) {
           this.variableLabel = variableLabel;
           }
          
           public String getVariableDescription() {
           return variableDescription;
           }
          
           public void setVariableDescription(String variableDescription) {
           this.variableDescription = variableDescription;
           }
          
           public boolean isUpdateState(){
           if (state==null){
           state="";
           return false;
           }
           return (getState().equals(updateState));
           }
          
           public String getState() {
           return state;
           }
          
           public void setState(String state) {
           this.state = state;
           }
          
           public Date getLastEffectiveDate() {
           return lastEffectiveDate;
           }
          
           public void setLastEffectiveDate(Date lastEffectiveDate) {
           this.lastEffectiveDate = lastEffectiveDate;
           }
          }
          


          • 3. Re: IllegalArgumentException: Stack must not be null
            Pete Muir Master

            ComponentTest doesn't support starting conversations. Try using a FacesRequest instead.