Putting array as an arg to the function in the java bytecode

130 Views Asked by At

I am trying to pass the array into the function using Jasmin bytecode. It generates a correct class but gives an error when I am trying to run it:

java.lang.VerifyError: (class: test4, method: main signature: ([Ljava/lang/String;)V) Register 1 contains wrong type

What can be an issue here? Thank you for your help in advance!

My bytecode:

.class public input_code
.super java/lang/Object

.method private static func([Ljava/lang/String;)V
.limit stack 99
.limit locals 99

return
.end method

.method public static main([Ljava/lang/String;)V
.limit stack 99
.limit locals 99

ldc 10
anewarray java/lang/String
astore 1
aload 1
ldc 9
ldc "t"
aastore
iload 1
invokestatic input_code/func([Ljava/lang/String;)V
return
.end method

java class:

public class input_code {
    private static void func(String[] var0) {
    }

    public static void main(String[] var0) {
        String[] var1 = new String[10];
        var1[9] = "t";
        func(var1);
    }
}
1

There are 1 best solutions below

0
Evgeny Barykin On

My bad here. I had a mistake in my code generator ( in visitExpIdentifier)

ldc "t"
aastore
iload 1 << should be aload