bastore : store in byte/boolean array : index : visitInsn()

Description
Takes a 32-bit int from the stack, truncates it to an 8-bit signed byte, and stores it in an array of bytes. arrayref is a reference to an array of bytes. index is an int. value is the int value to be stored in the array. arrayref, index and value are removed from the stack, and value is truncated to 8 bits and stored in the array at the given index.

bastore is also used to store values in boolean arrays. In this case, arrayref is a reference to an array of booleans (see the newarray instruction) . If value is zero, false is stored at the given index in the array, otherwise true is stored at the given index. In Sun's implementation, boolean arrays are actually stored as byte arrays, using one byte per boolean value. Other implementations might use packed arrays - or even int arrays - this is invisible to programs running on the JVM, which always use baload and bastore to access and store values in boolean arrays.
Exceptions
NullPointerException - arrayref is null

ArrayIndexOutOfBoundsException - index is < 0 or >= arrayref.length
Notes
2. Array indices start at 0 (the first entry in the array is at index 0).
See also
iastore lastore fastore dastore aastore castore sastore iaload laload faload daload aaload baload caload saload newarray
Stack
Before After
value ...
index ...
arrayref ...
... ...
Bytecode
Type Description
u1 bastore opcode = 0x54 (84)