Skip to content

Commit

Permalink
Support box/unbox for BIND vars wher eneeded -- fixes BYTEMAN-441
Browse files Browse the repository at this point in the history
  • Loading branch information
adinn committed May 28, 2024
1 parent 8fc0840 commit 3f236c9
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions agent/src/main/java/org/jboss/byteman/rule/binding/Binding.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,23 @@ public void compile(MethodVisitor mv, CompileContext compileContext) throws Comp
value.compile(mv, compileContext);
// plant check cast if required
if (doCheckCast) {
// we schedule a direct checkcast here rather than calling
// compileTypeConversion(value.type, type). the latter
// is fine when we are doing a downcast but does nothing
// if this is an 'upcast' i.e.when value.type is a subtype
// of type. We may still find doCheckCast set in that case
// because value.type requires access i.e. the value has
// been handled generically as an Object.
compileContext.compileCheckCast(type);
Type valueType = value.getType();
// as a special case we may be consuming a boxed type
// and trying to bind it as a primitive type or consuming
// a primitive type and trying to bind it as a boxed type.
// if so we need to plant a box or unbox
if (type.isPrimitive() != valueType.isPrimitive()) {
compileContext.compileTypeConversion(valueType, type);
} else {
// we schedule a direct checkcast here rather than calling
// compileTypeConversion(value.type, type). the latter
// is fine when we are doing a downcast but does nothing
// if this is an 'upcast' i.e.when value.type is a subtype
// of type. We may still find doCheckCast set in that case
// because value.type requires access i.e. the value has
// been handled generically as an Object.
compileContext.compileCheckCast(type);
}
}
Type type = this.type;
if (rule.requiresAccess(type)) {
Expand Down

0 comments on commit 3f236c9

Please sign in to comment.