Skip to content

Commit

Permalink
fix: allow calls to methods on arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
jumanji144 committed Aug 20, 2024
1 parent 332984a commit 5d8f8ca
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,6 @@ public void execute(MethodInstruction instruction) {
warn(instruction, "Cannot invoke method of 'null' reference");
else if (contextType instanceof PrimitiveType)
warn(instruction, "Cannot invoke method on primitive");
else if (contextType instanceof ArrayType)
warn(instruction, "Cannot invoke method on array");
}
if (methodType.returnType() != Types.VOID)
frame.pushType(methodType.returnType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,6 @@ public void execute(MethodInstruction instruction) {
warn(instruction, "Cannot invoke method of 'null' reference");
else if (contextType instanceof PrimitiveType)
warn(instruction, "Cannot invoke method on primitive");
else if (contextType instanceof ArrayType)
warn(instruction, "Cannot invoke method on array");
}

if (methodType.returnType() != Types.VOID) {
Expand Down
20 changes: 20 additions & 0 deletions jasm-composition-jvm/src/test/java/me/darknet/assembler/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.darknet.assembler;

public class Test {

public static void main(String[] args) {
exec(Test::example);
}

// the code we want to run
static void example() {
System.out.println("hi");
throw new RuntimeException();
}

// runs a runnable
static void exec(Runnable r) {
r.run();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.super java/lang/Object
.class public super Example {
.method callArrayMethod ()V {
parameters: { this },
code: {
A:
iconst_1
anewarray java/lang/String
// as a edge case, arrays are allowed to access all methods from Object
invokevirtual [Ljava/lang/String;.clone ()Ljava/lang/Object;
pop
return
B:
}
}
}

0 comments on commit 5d8f8ca

Please sign in to comment.