4

I have recently upgraded my project to Java 1.8 from 1.7.

I get an exception for inconsistent stackmap for a method in one of my Classes.

Initializing some unassigned local variables in the method resolved it, but can somebody please explain why use of unread variables raise an exception in Java 8, thanks.

It might well be with the eclipse version (Kepler SR 2 20140224-0627) that am using, just curious.

WorkAround

  1. was previously using '--xxSplitVerifier' (in 1.7) or '-noVerify' Jvm arguments before fixing the faulty code.

  2. if compiler preferences in eclipse workspace is unchecked with the option 'preserve unused local variables' it compiles fine with java 8

Method :

Cannot post complete method as its very big and restrained code of the company I'm with.

public synchronized int setData()  //sample code 
{
    int id= 0;
    StringBuffer sb;  // works if initialized - stringBuffer sb = null;
    String  name;     // works if name = null

    if (true) {
        sb = new StringBuffer();  
      } else {
        sb = new StringBuffer();
      }  

stackFrame :

Caused by: java.lang.VerifyError: Inconsistent stackmap frames at branch target 2079

Exception Details: Location: someClass.setData(someClass/Data)I @2079: iload_3

Reason: Type top (current frame, locals[4]) is not assignable to 'java/lang/StringBuffer' (stack map, locals[4])

Current Frame: bci: @98 flags: { } locals: { 'someClass/setData', 'someClass/Data', 'someClass/Data', integer, top, top } stack: { 'someClass/Data' }

Stackmap Frame: bci: @2079 flags: { } locals: { 'someClass/setData', 'someClass/Data', 'someClass/Data', integer, 'java/lang/StringBuffer', 'java/lang/String'} stack: { } Bytecode: 0x0000000: 2bb6 032b 4d03 3e06 bd01 3e59 0313 032f 0x0000010: 5359 0413 0331 5359 0513 0333 533a 0606

Rk R Bairi
  • 1,289
  • 7
  • 15
  • 39
  • 2
    This seems more like a bug than anything else. Have you reported this to Oracle? – Makoto Nov 10 '16 at 17:55
  • What did you compile the class with? – biziclop Nov 10 '16 at 17:55
  • 3
    I can't reproduce it with the code given and the standard compiler. Can you run `javap -c -l -s -v` on the compiled, faulty class? – biziclop Nov 10 '16 at 18:04
  • Yes I ran javap on the .class. It gave a more detailed list of locals and stacks in the method with stackframe just as above in the question. – Rk R Bairi Nov 10 '16 at 18:48
  • I doubt that this method, not even having a return type, compiles at all. You should provide the *exact code* for allowing us to reproduce the problem. If you just copy the actual code to your brower, such mistakes can’t happen. Further, you should specify the exact Eclipse version that causes that problem. I have the strong suspicion, that it is quite an old version, Kepler or even older… – Holger Nov 10 '16 at 19:21
  • Eclipse Kepler SR 2 20140224-0627. It might very well be the version. The method has code which compiles and returns an int. Could not post the complete method as its pretty big. – Rk R Bairi Nov 10 '16 at 20:26
  • Once upon a time, we had problems with the Eclipse compiler and stack maps too; the clean canonical solution was to update Eclipse. The entire purpose of the option to turn off the SplitVerifier was to give tool vendors and clients time to update. With Java 8 it was considered that there have been enough time. I strongly suggest updating Eclipse. – Holger Nov 14 '16 at 16:47
  • Sure. Eclipse Kepler supported Java 8, only after I installed a patch to get new compiler features. Will change to a latest compatible version. Thanks @Holger – Rk R Bairi Nov 14 '16 at 20:08

1 Answers1

0

Assuming you are using OpenJDK - most likely you have hit compiler bug JDK-8160699. Resolution is then to upgrade to a newer JDK version.

tbsalling
  • 4,477
  • 4
  • 30
  • 51