java - Why won't this bytecode verify -


edit: solution using aastore, when should have been using iastore, because wanted store item in array of ints, while aastore arrays of objects.

i have following method i'm generating constructor in bytecode

aload_0 invokespecial java/lang/object/<init>()v aload_0 new java/lang/stringbuilder dup invokespecial java/lang/stringbuilder/<init>()v putfield com/js/interpreter/custom_types/1e9ebd0/s ljava/lang/stringbuilder; aload_0 iconst_0 putfield com/js/interpreter/custom_types/1e9ebd0/l aload_0 iconst_0 multianewarray [i 1 astore_1 iconst_0 istore_2 goto 23 18:aload_1 iload_2 iconst_0 aastore iinc 2 1 23:iload_2 iconst_0 if_icmplt 18 aload_1 putfield com/js/interpreter/custom_types/1e9ebd0/a [i return 

however, fails verify, giving method: signature: ()v) expecting find object/array on stack

however, can go through , know precisely number of items on stack @ times:

    aload_0 1     invokespecial java/lang/object/<init>()v 0     aload_0 1     new java/lang/stringbuilder 2     dup 3     invokespecial java/lang/stringbuilder/<init>()v 2     putfield com/js/interpreter/custom_types/1e9ebd0/s ljava/lang/stringbuilder; 0     aload_0 1     iconst_0 2     putfield com/js/interpreter/custom_types/1e9ebd0/l 0     aload_0 1     iconst_0 2     multianewarray [i 1 2     astore_1 1     iconst_0 2     istore_2 1     goto 23     18:aload_1 2     iload_2 3     iconst_0 4     aastore 1     iinc 2 1 1     23:iload_2 2     iconst_0 3     if_icmplt 18 1     aload_1 2     putfield com/js/interpreter/custom_types/1e9ebd0/a [i 0     return 

when run through justice verifier, doesn't give me useful messages (and fails verify classes generated javac).

what going on here? what's problem?

i don't see problem, here's when sucked bytecode-debugging hell:

  • omit unnecessary code. seems loop nop (you never enter body loop because initialize local variable 2 zero, right?). make body of loop empty , see if verification bug persists.
  • then, start removing other pieces (the initialization of various fields), until bug disappears.

Comments