From ecd733a236b3963c36ad869e05d14d1f49e99a92 Mon Sep 17 00:00:00 2001 From: chibash Date: Wed, 15 Jul 2015 15:45:22 +0900 Subject: [PATCH] fixed JIRA JASSIST-249 --- src/main/javassist/compiler/TypeChecker.java | 2 +- src/test/javassist/JvstTest5.java | 9 +++++++++ src/test/test5/BoolTest.java | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/test/test5/BoolTest.java diff --git a/src/main/javassist/compiler/TypeChecker.java b/src/main/javassist/compiler/TypeChecker.java index d2814626..bd62f806 100644 --- a/src/main/javassist/compiler/TypeChecker.java +++ b/src/main/javassist/compiler/TypeChecker.java @@ -502,7 +502,7 @@ public class TypeChecker extends Visitor implements Opcode, TokenId { else insertCast(expr, type1, type2); - if (CodeGen.isP_INT(exprType)) + if (CodeGen.isP_INT(exprType) && exprType != BOOLEAN) exprType = INT; // type1 may be BYTE, ... } diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java index fcbbbb99..cefc84fc 100644 --- a/src/test/javassist/JvstTest5.java +++ b/src/test/javassist/JvstTest5.java @@ -91,4 +91,13 @@ public class JvstTest5 extends JvstTestRoot { Object obj = make(cc.getName()); assertEquals(0, invoke(obj, "say")); } + + public void testJIRA249() throws Exception { + CtClass cc = sloader.get("test5.BoolTest"); + CtMethod testMethod = cc.getDeclaredMethod("test"); + testMethod.insertBefore("i = foo(true & true);"); + cc.writeFile(); + Object obj = make(cc.getName()); + assertEquals(1, invoke(obj, "run")); + } } diff --git a/src/test/test5/BoolTest.java b/src/test/test5/BoolTest.java new file mode 100644 index 00000000..0d9ca154 --- /dev/null +++ b/src/test/test5/BoolTest.java @@ -0,0 +1,15 @@ +package test5; + +public class BoolTest { + static boolean i = false; + public boolean test() { + return i; + } + public boolean foo(boolean b) { return b; } + public int run() { + if (test()) + return 1; + else + return 0; + } +} -- 2.39.5