]> source.dussan.org Git - javassist.git/commitdiff
fixes JASSIST-255 Primitive array return values cause invalid cast to Object
authorchibash <chiba@javassist.org>
Mon, 7 Dec 2015 15:10:58 +0000 (00:10 +0900)
committerchibash <chiba@javassist.org>
Mon, 7 Dec 2015 15:10:58 +0000 (00:10 +0900)
Readme.html
src/main/javassist/compiler/CodeGen.java
src/test/javassist/JvstTest5.java
src/test/test5/InvalidCastDollar.java [new file with mode: 0644]
tutorial/tutorial2.html

index c30465028005e44e0e5f5ae8a27317cc54b8af07..7817178b92889a9a98a1a1fab31818f84f8792f7 100644 (file)
@@ -283,7 +283,7 @@ see javassist.Dump.
 
 <p>-version 3.21
 <ul>
-<li>JIRA JASSIST-244, 248
+<li>JIRA JASSIST-244, 248, 255
 </ul>
 </p>
 
index d2bdea9a35a0e9f6b1177270c0da368fa7288b0d..e02884de258b644c8a961c6ed1aa63bdea7be6d7 100644 (file)
@@ -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);
index 6deffcabb98e6a126d8795ecb887773efcb74e21..8e1ef8a7f9490ebb8ecf0b0276bf3ccece15bd4a 100644 (file)
@@ -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 (file)
index 0000000..9633189
--- /dev/null
@@ -0,0 +1,11 @@
+package test5;
+
+public class InvalidCastDollar {
+    public static byte[] arrayReturn() {
+        return new byte[12];
+    }
+
+    public static int intReturn() {
+        return 23;
+    }
+}
index 9a962ac322d91ca0eee1e98500309207a4d3a517..f92f96e9b2433a3e515c179770ad876e4d9cde53 100644 (file)
@@ -481,7 +481,7 @@ compiled code at the end of the method.  In the statement given to
 available.
 
 <p>The variable <code>$_</code> 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 <code>void</code>,
 then the type of <code>$_</code> is <code>Object</code> and the value