Skip to content

Commit

Permalink
improve type checking & conversion - fixes BYTEMAN-443
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed Jan 7, 2025
1 parent 9442c7e commit 58d6e45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void compileNumericConversion(Type fromType, Type toType)
}
}
if (box) {
if (toType == Type.NUMBER) {
if (toType == Type.NUMBER || toType == Type.OBJECT) {
// special case! nothing to do
} else {
// convert from one numeric object type to another
Expand All @@ -164,7 +164,7 @@ public void compileNumericConversion(Type fromType, Type toType)
if (toType == Type.CHARACTER) {
compilePrimitiveConversion(fromType, Type.C);
compileBox(toType);
} else if (toType == Type.NUMBER) {
} else if (toType == Type.NUMBER || toType == Type.OBJECT) {
// special case! convert primitive to it's numeric box type
toType = Type.boxType(fromType);
compileBox(toType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,14 @@ private static byte[] compileBytes(Rule rule, Class helperClass, String helperNa
// treat inaccessible classes generically
type = org.jboss.byteman.rule.type.Type.OBJECT;
} else {
cc.compileTypeConversion(org.jboss.byteman.rule.type.Type.OBJECT, type);
if (type.isPrimitive()) {
// convert from object to the relevant primitive type
cc.compileTypeConversion(org.jboss.byteman.rule.type.Type.OBJECT, type);
} else {
// we know the value is of the correct type
// simply plant a checkcast keep the verifier happy
cc.compileCheckCast(type);
}
}
mv.visitFieldInsn(PUTFIELD, compiledHelperName, name, type.getInternalName(true, true));
if (type.getNBytes() > 4) {
Expand Down

0 comments on commit 58d6e45

Please sign in to comment.