From da74898f9dfb949814388a5b42f69bdd05638874 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Mon, 8 Apr 2024 13:18:27 +0200 Subject: [PATCH] Fix #312 --- resources/bytecode/javFiles/Bug312.jav | 8 ++++++++ src/main/java/de/dhbwstuttgart/bytecode/Codegen.java | 5 ++++- src/test/java/TestComplete.java | 8 ++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 resources/bytecode/javFiles/Bug312.jav diff --git a/resources/bytecode/javFiles/Bug312.jav b/resources/bytecode/javFiles/Bug312.jav new file mode 100644 index 00000000..82f1aa24 --- /dev/null +++ b/resources/bytecode/javFiles/Bug312.jav @@ -0,0 +1,8 @@ +public class Bug312 { + Bug312A i = new Bug312A(); + public main() { + if (i == null) {} + } +} + +class Bug312A {} \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java index 601316f6..fd5e737f 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/Codegen.java @@ -281,9 +281,12 @@ public class Codegen { return TargetType.Float; } else if (left.equals(TargetType.Long) || right.equals(TargetType.Long)) { return TargetType.Long; - } else { + } else if (left.equals(TargetType.Integer) || right.equals(TargetType.Integer)) { return TargetType.Integer; + } else if (left.equals(TargetType.Short) || right.equals(TargetType.Short)) { + return TargetType.Short; } + return left; } private void generateBinaryOp(State state, TargetBinaryOp op) { diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index f06f1a19..a5c38489 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -1039,4 +1039,12 @@ public class TestComplete { var instance = clazz.getDeclaredConstructor().newInstance(); assertEquals(clazz.getDeclaredMethod("toString").invoke(instance), "3"); } + + @Test + public void testBug312() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Bug312.jav"); + var clazz = classFiles.get("Bug312"); + var instance = clazz.getDeclaredConstructor().newInstance(); + clazz.getDeclaredMethod("main").invoke(instance); + } }