@@ -294,6 +294,9 @@ public static MutableBytes of(int... bytes) {
294294 */
295295 public void set (int index , Bytes bytes ) {
296296 checkNotNull (bytes );
297+ if (bytes .isEmpty ()) {
298+ return ;
299+ }
297300 checkElementIndex (index , length );
298301 checkArgument (
299302 index + bytes .size () <= length ,
@@ -316,6 +319,9 @@ public void set(int index, Bytes bytes) {
316319 */
317320 public void set (int index , byte [] bytes ) {
318321 checkNotNull (bytes );
322+ if (bytes .length == 0 ) {
323+ return ;
324+ }
319325 checkElementIndex (index , length );
320326 checkArgument (
321327 index + bytes .length <= length ,
@@ -378,6 +384,24 @@ public void setLong(int index, long value) {
378384 set (index , (byte ) (value & 0xFF ));
379385 }
380386
387+ /**
388+ * Set a byte in this value.
389+ *
390+ * @param index The index of the byte to set.
391+ * @param b The value to set that byte to.
392+ * @throws IndexOutOfBoundsException if {@code i < 0} or {i >= size()}.
393+ */
394+ public void set (int index , byte b ) {
395+ checkElementIndex (index , length );
396+ if (index > (length - 1 )) {
397+ throw new IndexOutOfBoundsException (
398+ format (
399+ "Value of size %s has not enough bytes to write a 4 bytes int from index %s" ,
400+ length , index ));
401+ }
402+ bytesArray [offset + index ] = b ;
403+ }
404+
381405 /**
382406 * Increments the value of the bytes by 1, treating the value as big endian.
383407 *
@@ -724,17 +748,6 @@ public int size() {
724748 return length ;
725749 }
726750
727- /**
728- * Set a byte in this value.
729- *
730- * @param i The index of the byte to set.
731- * @param b The value to set that byte to.
732- * @throws IndexOutOfBoundsException if {@code i < 0} or {i >= size()}.
733- */
734- public void set (int i , byte b ) {
735- bytesArray [offset + i ] = b ;
736- }
737-
738751 @ Override
739752 public byte get (int i ) {
740753 return bytesArray [offset + i ];
0 commit comments