Skip to main content

lambda-8-b45: VerifyError regarding java.lang.Iterable

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
sherrmann
Offline
Joined: 2012-07-03

Using the lambda enabled JDK I can't run any program that touches java.lang.Iterable via a 1.5-compiled class.

Test case:

package jdk18bug;
public class VerifyBug {
    static class MyIterable implements java.lang.Iterable<String> {
        public java.util.Iterator<String> iterator() {
            return null;
        }
    }
    public static void main(String[] args) {
        System.out.println(new MyIterable());
    }
}

Compile with -source 1.5 -target 1.5.

Running the program yields this error:

Exception in thread "main" java.lang.VerifyError: (class: jdk18bug/VerifyBug$MyIterable, method: count signature: ()J) Stack size too large
        at jdk18bug.VerifyBug.main(VerifyBug.java:9)

Points to observe:

  • the error message is pretty far off: there's no method count in MyIterable, nor is stack size really the problem
  • java.lang.Iterable.count() is a default method, in the byte code it has the modifiers ACC_PUBLIC and ACC_INTERFACE set. The latter is not backed by the JSR 335 draft spec 0.5.1.
  • if VerifyBug.java is compiled with -target 6 or above the bug does not occur, but aren't default methods being introduced for the sake of enabling old code linked against new libraries?

best,
Stephan