From 01e374eadd5cfaac5dbddc9e7ef5730ba482bb30 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Mon, 18 Mar 2024 10:14:40 +0100 Subject: [PATCH] Fix #296 --- resources/bytecode/javFiles/Bug296.jav | 11 +++++++++++ src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 3 ++- src/test/java/TestComplete.java | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 resources/bytecode/javFiles/Bug296.jav diff --git a/resources/bytecode/javFiles/Bug296.jav b/resources/bytecode/javFiles/Bug296.jav new file mode 100644 index 00000000..35ac8826 --- /dev/null +++ b/resources/bytecode/javFiles/Bug296.jav @@ -0,0 +1,11 @@ +import java.lang.Integer; + +public class Bug296 { + public static m1() { + return m2(); + } + + static m2() { + return 10; + } +} diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 52bffb30..2ff2d0a9 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -1008,7 +1008,8 @@ public class Codegen { break; } case TargetMethodCall call: { - generate(state, call.expr()); + if (!call.isStatic()) + generate(state, call.expr()); for (var i = 0; i < call.args().size(); i++) { var e = call.args().get(i); var arg = call.parameterTypes().get(i); diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index f675128c..1c031203 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -940,4 +940,11 @@ public class TestComplete { var clazz = classFiles.get("Bug293"); var instance = clazz.getDeclaredConstructor().newInstance(); } + + @Test + public void testBug296() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug296.jav"); + var clazz = classFiles.get("Bug296"); + clazz.getDeclaredMethod("m1").invoke(null); + } }