Skip to content

Commit

Permalink
fix(engine): fixing how we compare byte arrays
Browse files Browse the repository at this point in the history
Using Guava UnsignedBytes.compare instead of comparing signed bytes
  • Loading branch information
ana-vinogradova-camunda committed Jan 12, 2024
1 parent 67c23d8 commit e82cc5c
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package io.camunda.zeebe.process.test.engine.db;

import com.google.common.primitives.UnsignedBytes;
import io.camunda.zeebe.db.DbValue;
import java.util.Arrays;
import org.agrona.ExpandableArrayBuffer;
Expand All @@ -20,6 +21,11 @@ private Bytes(final byte[] byteArray) {
this.byteArray = byteArray;
}

@Override
public int hashCode() {
return Arrays.hashCode(byteArray);
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -34,11 +40,6 @@ public boolean equals(final Object o) {
return Arrays.equals(byteArray, bytes.byteArray);
}

@Override
public int hashCode() {
return Arrays.hashCode(byteArray);
}

@Override
public int compareTo(final Bytes other) {

Expand All @@ -56,9 +57,10 @@ public int compareTo(final Bytes other) {
final byte ourByte = byteArray[i];
final byte otherByte = otherByteArray[i];

if (ourByte < otherByte) {
final int compared = UnsignedBytes.compare(ourByte, otherByte);
if (compared < 0) {
return SMALLER;
} else if (ourByte > otherByte) {
} else if (compared > 0) {
return BIGGER;
} // else { // = equals -> continue }
}
Expand Down

0 comments on commit e82cc5c

Please sign in to comment.