title: What causes this error : java.lang.VerifyError: Inconsistent stack height 2 != 1?
body: <p>I use ASM to generate byte code for while() statement. But eclipse reports:</p>
  
  <pre><code>Exception in thread "main" java.lang.VerifyError: (class: show_cise_image, method: main signature: ([Ljava/lang/String;)V) Inconsistent stack height 2 != 1
      at java.lang.Class.getDeclaredMethods0(Native Method)
            ..................
  </code></pre>
  
  <p>My source code for byte code:</p>
  
  <pre><code>show_cise_image {
      boolean flag;
      flag =  true;
      while(flag){
          flag = false;   
      }    
  }
  </code></pre>
  
  <p>generated byte code for above code:</p>
  
  <pre><code>/ class version 51.0 (51)
  // access flags 0x21
  public class show_cise_image {
  
  
    // access flags 0x8
    static int v = 0
  
    // access flags 0x8
    static boolean flag = 0
  
    // access flags 0x9
    public static main(String[]) : void
     L0
      LINENUMBER 6 L0
      GETSTATIC show_cise_image.flag : boolean
      LDC 1
      PUTSTATIC show_cise_image.flag : boolean
      GOTO L1
     L2
      GETSTATIC show_cise_image.flag : boolean
      LDC 0
      PUTSTATIC show_cise_image.flag : boolean
     L1
      GETSTATIC show_cise_image.flag : boolean
      IFNE L2
      RETURN
     L3
      LOCALVARIABLE args String[] L0 L3 2
      LOCALVARIABLE x int L0 L3 0
      LOCALVARIABLE y int L0 L3 1
      MAXSTACK = 3
      MAXLOCALS = 3
  }
  </code></pre>
  
  <p>my java code to generate byte code(I think this error is caused by while() statement,     so I just post this part):</p>
  
  <pre><code>/* while(Expr){ stmt*}  */
  
  @Override
      public Object visitIterationStmt(IterationStmt iterationStmt, Object arg)
              throws Exception {
          MethodVisitor mv = (MethodVisitor)arg;
          Label guardLabel = new Label();
          Label bodyLabel = new Label();
          mv.visitJumpInsn(GOTO, guardLabel);
  
          mv.visitLabel(bodyLabel);
          for(Stmt t : iterationStmt.stmtList)
              t.visit(this, mv);   // execute statements in body
  
          mv.visitLabel(guardLabel);
          iterationStmt.expr.visit(this, mv);  // put the result of expr on stack
          mv.visitJumpInsn(IFNE, bodyLabel);
          return null;
      }
  </code></pre>