Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 383629

Summary: java.lang.VerifyError: JVMVRFY012 stack shape inconsistent
Product: [Eclipse Project] JDT Reporter: Tim De Vos <tim.devos>
Component: CoreAssignee: Ayushman Jain <amj87.iitr>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, Olivier_Thomann, satyam.kandula, srikanth_sankaran
Version: 3.7.2   
Target Milestone: 3.8.1   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Tim De Vos CLA 2012-06-27 06:00:07 EDT
Build Identifier: org.eclipse.platform (3.7.2.v20120207)

When I compile/run with Eclipse on Java 1.7 target I got the following exception:

java.lang.VerifyError: JVMVRFY012 stack shape inconsistent

In my IDE, I use the Java 1.7.0_4 release. When I compile it on the command line with javac it works fine. Also if I change the target release to 1.6 it also works fine. 


Reproducible: Always

Steps to Reproduce:
1. Create a class

package com.tdv;

import java.io.IOException;
import java.nio.CharBuffer;

public class Java7Test {
     public static void main(String[] args) {           
         CharBuffer cbuf = CharBuffer.allocate(100);
         cbuf.append("TEST");
         
         try {
         Java7Printer.print(cbuf);
      } catch (IOException e) {
         e.printStackTrace();
      }
      }
} 
2. and a class
package com.tdv;

import java.io.IOException;
import java.nio.CharBuffer;

public class Java7Printer {
   protected static String print(CharBuffer buf) throws IOException {
      try {
         System.out.println("TEST");
      }
      catch(Exception e) {
         throw new IOException("ERROR OCCURED");
      }
      
      return "RETURN_VALUE";
   }
   
   protected static String decode(CharBuffer buf) {
      char ch, chc;         
      boolean escaping = false;         
      StringBuffer sb = new StringBuffer();                  
      boolean done = false;
      
      do {
         ch = buf.get();                           
         if (escaping) {                                             
            switch (ch) {                                             
            case '\n':                  
               do {
                  chc = buf.get();
               } while ( (chc == '\r') || (chc == '\n') );
               buf.position ( buf.position() - 1 );
               break;
            default:
            }               
         } else {               
            switch (ch) {                  
               case '\r':
                  break;
               default:
            }               
         }
         done = true;
      } while (!done);

      return sb.toString();         
   }
}

3. Now run it and you'll get the exception.
Comment 1 Satyam Kandula CLA 2012-06-27 06:58:36 EDT
I am able to reproduce this problem even with 3.8.
Comment 2 Srikanth Sankaran CLA 2012-06-27 07:01:55 EDT
Thanks for the report, I'll investigate.
Comment 3 Srikanth Sankaran CLA 2012-06-27 07:48:56 EDT
A smaller program:

// ---------------- 8< -------------------
public class X {
  public static void main(String[] args) {           
    char  chc;         
     do {                         
        if (args == null) {                                             
           switch ('a') {                                             
           case '\n':                  
                 chc = 'b';
           }               
        } else {               
           switch ('a') {                  
              case '\r':
           }               
        }
     } while (false);
     System.out.println("Done");
  }
}
Comment 4 Olivier Thomann CLA 2012-06-27 09:07:30 EDT
The problem comes from the initialization range of the variable 'chc':

  // Method descriptor #15 ([Ljava/lang/String;)V
  // Stack: 2, Locals: 2
  public static void main(java.lang.String[] args);
     0  aload_0 [args]
     1  ifnonnull 30
     4  bipush 97
     6  tableswitch default: 27
          case 10: 24
    24  bipush 98
    26  istore_1 [chc]
    27  goto 52
    30  bipush 97
    32  tableswitch default: 52
          case 13: 52
    52  getstatic java.lang.System.out : java.io.PrintStream [16]
    55  ldc <String "Done2"> [22]
    57  invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]
    60  return
      Line numbers:
        [pc: 0, line: 5]
        [pc: 4, line: 6]
        [pc: 24, line: 8]
        [pc: 30, line: 12]
        [pc: 52, line: 17]
        [pc: 60, line: 18]
      Local variable table:
        [pc: 0, pc: 61] local: args index: 0 type: java.lang.String[]
        [pc: 27, pc: 30] local: chc index: 1 type: char
      Stack map table: number of frames 4
        [pc: 24, same]
        [pc: 27, append: {int}]
        [pc: 30, chop 1 local(s)]
        [pc: 52, same]

At pc 27, 'chc' range should be closed. So we would end up with an empty range and then the local variable entry would not show up.
This might be the same kind of fix than the one for bug 380927.
Comment 5 Olivier Thomann CLA 2012-06-27 09:33:42 EDT
This is actually a duplicate of bug 381172. The fix for bug 381172 also fixes this issue.
Comment 6 Ayushman Jain CLA 2012-06-27 09:38:18 EDT
(In reply to comment #5)
> This is actually a duplicate of bug 381172. The fix for bug 381172 also fixes
> this issue.

Thanks Olivier! Srikanth, I can take care of both these bugs

*** This bug has been marked as a duplicate of bug 381172 ***
Comment 7 Srikanth Sankaran CLA 2012-06-27 10:02:04 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > This is actually a duplicate of bug 381172. The fix for bug 381172 also fixes
> > this issue.
> 
> Thanks Olivier! Srikanth, I can take care of both these bugs

Thank you. Please remember to add the test case from here to the junits.
Comment 8 Srikanth Sankaran CLA 2012-08-16 02:04:24 EDT
Verified for 3.8.1 using Build id: M20120815-1000