bool[] requires boolean[] but found Boolean[]
muyu66 opened this issue · 2 comments
this version is 9.1.1.
i try f.encodeCall(Tuple.singleton(w))
, w is new Boolean[]{false}
, An error has occurred, as shown below.
Of course, it's OK to use primitive types, such as new boolean[]{false}
.
In addition, it is no problem for non arrays, that is, it does not distinguish between Boolean and boolean
So, please support indistinguishable boolean as method encoding input parameter
The mistake of the original text is
tuple index 0: class mismatch: [Ljava.lang.Boolean; != [Z (bool[] requires boolean[] but found Boolean[]) java.lang.IllegalArgumentException: tuple index 0: class mismatch: [Ljava.lang.Boolean; != [Z (bool[] requires boolean[] but found Boolean[]) at com.esaulpaugh.headlong.abi.TupleType.countBytes(TupleType.java:139) at com.esaulpaugh.headlong.abi.TupleType.countBytes(TupleType.java:127) at com.esaulpaugh.headlong.abi.TupleType.validate(TupleType.java:146) at com.esaulpaugh.headlong.abi.Function.validatedCallLength(Function.java:193) at com.esaulpaugh.headlong.abi.Function.encodeCall(Function.java:205)
This branch shows how to change the type of bool[] from boolean[] to Boolean[]: https://github.com/esaulpaugh/headlong/tree/boolean-object-array
Trying to support multiple Java types for the same ABIType is probably not a good idea. And Integer[]
and Long[]
would have to be supported as well, for consistency. These types of arrays are rarely used.
The fact that non-array types boolean
and Boolean
are both accepted is really just a byproduct of autoboxing.
What you could do, though, is fork the code and modify Tuple
to automatically convert any Boolean[]
to boolean[]
(recursively). But if you decode the resulting encoding, you would end up with boolean[]
instead of the input type Boolean[]
I see. I already know