Browse Source

fixes JASSIST-255 Primitive array return values cause invalid cast to Object

tags/rel_3_21_0-java9-ea
chibash 3 years ago
parent
commit
4cf21faf54

+ 1
- 1
Readme.html View File

@@ -283,7 +283,7 @@ see javassist.Dump.
283 283
 
284 284
 <p>-version 3.21
285 285
 <ul>
286
-<li>JIRA JASSIST-244, 248
286
+<li>JIRA JASSIST-244, 248, 255
287 287
 </ul>
288 288
 </p>
289 289
 

+ 2
- 1
src/main/javassist/compiler/CodeGen.java View File

@@ -1420,12 +1420,13 @@ public abstract class CodeGen extends Visitor implements Opcode, TokenId {
1420 1420
         int type = expr.getType();
1421 1421
         oprand.accept(this);
1422 1422
         int srcType = exprType;
1423
+        int srcDim = arrayDim;
1423 1424
         if (invalidDim(srcType, arrayDim, className, type, dim, name, true)
1424 1425
             || srcType == VOID || type == VOID)
1425 1426
             throw new CompileError(msg);
1426 1427
 
1427 1428
         if (type == CLASS) {
1428
-            if (!isRefType(srcType))
1429
+            if (!isRefType(srcType) && srcDim == 0)
1429 1430
                 throw new CompileError(msg);
1430 1431
 
1431 1432
             return toJvmArrayName(name, dim);

+ 7
- 0
src/test/javassist/JvstTest5.java View File

@@ -135,4 +135,11 @@ public class JvstTest5 extends JvstTestRoot {
135 135
         Object obj = make(cc.getName());
136 136
         assertEquals(40271, invoke(obj, "run"));
137 137
     }
138
+
139
+    public void testInvalidCastWithDollar() throws Exception {
140
+        String code = "{ new JavassistInvalidCastTest().inspectReturn((Object) ($w) $_); } ";
141
+        CtClass c = sloader.get("test5.InvalidCastDollar");
142
+        for (CtMethod method : c.getDeclaredMethods())
143
+            method.insertAfter(code);
144
+    }
138 145
 }

+ 11
- 0
src/test/test5/InvalidCastDollar.java View File

@@ -0,0 +1,11 @@
1
+package test5;
2
+
3
+public class InvalidCastDollar {
4
+    public static byte[] arrayReturn() {
5
+        return new byte[12];
6
+    }
7
+
8
+    public static int intReturn() {
9
+        return 23;
10
+    }
11
+}

+ 1
- 1
tutorial/tutorial2.html View File

@@ -481,7 +481,7 @@ compiled code at the end of the method.  In the statement given to
481 481
 available.
482 482
 
483 483
 <p>The variable <code>$_</code> represents the resulting value of the
484
-method.  So it is a write-only variable.
484
+method.
485 485
 The type of that variable is the type of the result type (the
486 486
 return type) of the method.  If the result type is <code>void</code>,
487 487
 then the type of <code>$_</code> is <code>Object</code> and the value

Loading…
Cancel
Save