From 4cf21faf5416cb73988ba7556fdb91f6f604b311 Mon Sep 17 00:00:00 2001
From: chibash
Date: Tue, 8 Dec 2015 00:10:58 +0900
Subject: fixes JASSIST-255 Primitive array return values cause invalid cast to
Object
---
Readme.html | 2 +-
src/main/javassist/compiler/CodeGen.java | 3 ++-
src/test/javassist/JvstTest5.java | 7 +++++++
src/test/test5/InvalidCastDollar.java | 11 +++++++++++
tutorial/tutorial2.html | 2 +-
5 files changed, 22 insertions(+), 3 deletions(-)
create mode 100644 src/test/test5/InvalidCastDollar.java
diff --git a/Readme.html b/Readme.html
index c3046502..7817178b 100644
--- a/Readme.html
+++ b/Readme.html
@@ -283,7 +283,7 @@ see javassist.Dump.
-version 3.21
-- JIRA JASSIST-244, 248
+
- JIRA JASSIST-244, 248, 255
diff --git a/src/main/javassist/compiler/CodeGen.java b/src/main/javassist/compiler/CodeGen.java
index d2bdea9a..e02884de 100644
--- a/src/main/javassist/compiler/CodeGen.java
+++ b/src/main/javassist/compiler/CodeGen.java
@@ -1420,12 +1420,13 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
int type = expr.getType();
oprand.accept(this);
int srcType = exprType;
+ int srcDim = arrayDim;
if (invalidDim(srcType, arrayDim, className, type, dim, name, true)
|| srcType == VOID || type == VOID)
throw new CompileError(msg);
if (type == CLASS) {
- if (!isRefType(srcType))
+ if (!isRefType(srcType) && srcDim == 0)
throw new CompileError(msg);
return toJvmArrayName(name, dim);
diff --git a/src/test/javassist/JvstTest5.java b/src/test/javassist/JvstTest5.java
index 6deffcab..8e1ef8a7 100644
--- a/src/test/javassist/JvstTest5.java
+++ b/src/test/javassist/JvstTest5.java
@@ -135,4 +135,11 @@ public class JvstTest5 extends JvstTestRoot {
Object obj = make(cc.getName());
assertEquals(40271, invoke(obj, "run"));
}
+
+ public void testInvalidCastWithDollar() throws Exception {
+ String code = "{ new JavassistInvalidCastTest().inspectReturn((Object) ($w) $_); } ";
+ CtClass c = sloader.get("test5.InvalidCastDollar");
+ for (CtMethod method : c.getDeclaredMethods())
+ method.insertAfter(code);
+ }
}
diff --git a/src/test/test5/InvalidCastDollar.java b/src/test/test5/InvalidCastDollar.java
new file mode 100644
index 00000000..9633189e
--- /dev/null
+++ b/src/test/test5/InvalidCastDollar.java
@@ -0,0 +1,11 @@
+package test5;
+
+public class InvalidCastDollar {
+ public static byte[] arrayReturn() {
+ return new byte[12];
+ }
+
+ public static int intReturn() {
+ return 23;
+ }
+}
diff --git a/tutorial/tutorial2.html b/tutorial/tutorial2.html
index 9a962ac3..f92f96e9 100644
--- a/tutorial/tutorial2.html
+++ b/tutorial/tutorial2.html
@@ -481,7 +481,7 @@ compiled code at the end of the method. In the statement given to
available.
The variable $_
represents the resulting value of the
-method. So it is a write-only variable.
+method.
The type of that variable is the type of the result type (the
return type) of the method. If the result type is void
,
then the type of $_
is Object
and the value
--
cgit v1.2.3