A RULE local var binding may sometimes attempt to downcast an initializater value during initial assignment of the variable. This is particularly likely when the initializer is a ternary ?: expression with one of the limbs having type null. The interpret method for Binding attempts to ensure that the value is assignable to the downcast type by calling Class.isInstance. This works if the value is non-null but results in a ClassCastException if the value is null.
Note that this problem does not occur when the rule is compiled to bytecode. The checkcast instruction planted to ensure assignability allows null vales to pass through.
Original discussion follows:
I have the following rule definition:
The return type of `io.opentracing.contrib.specialagent.Agent.findClass($0, $1)` is `byte`.
Upon the type check phase, I receive the following exception:
If I remove the explicit mention of `byte` from the rule, it seems to pass the type check, but then I receive the following exception during the interpret phase:
I'm not sure whether this is a bug, or my oversight regarding a detail of the Byteman rule semantics that I'm missing here.
Why is the type check failing when `byte` is explicitly specified in the rule?
When the explicit `byte` type is removed from the rule, why would `null` fail to be cast to `byte`? It seems that the type assignment in this case is not correct.