Browse Source

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

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

+ 1
- 1
Readme.html View File



<p>-version 3.21 <p>-version 3.21
<ul> <ul>
<li>JIRA JASSIST-244, 248
<li>JIRA JASSIST-244, 248, 255
</ul> </ul>
</p> </p>



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

int type = expr.getType(); int type = expr.getType();
oprand.accept(this); oprand.accept(this);
int srcType = exprType; int srcType = exprType;
int srcDim = arrayDim;
if (invalidDim(srcType, arrayDim, className, type, dim, name, true) if (invalidDim(srcType, arrayDim, className, type, dim, name, true)
|| srcType == VOID || type == VOID) || srcType == VOID || type == VOID)
throw new CompileError(msg); throw new CompileError(msg);


if (type == CLASS) { if (type == CLASS) {
if (!isRefType(srcType))
if (!isRefType(srcType) && srcDim == 0)
throw new CompileError(msg); throw new CompileError(msg);


return toJvmArrayName(name, dim); return toJvmArrayName(name, dim);

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

Object obj = make(cc.getName()); Object obj = make(cc.getName());
assertEquals(40271, invoke(obj, "run")); 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);
}
} }

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

package test5;

public class InvalidCastDollar {
public static byte[] arrayReturn() {
return new byte[12];
}

public static int intReturn() {
return 23;
}
}

+ 1
- 1
tutorial/tutorial2.html View File

available. available.


<p>The variable <code>$_</code> represents the resulting value of the <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 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>, 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 then the type of <code>$_</code> is <code>Object</code> and the value

Loading…
Cancel
Save