googleapis / googleapis/java-bigtable-hbase

bigtable-hbase-2.x:2.6.1 FuzzyRowFilterAdapter is not adapting correctly when using `--illegal-access=deny`

Open
#3,780 0 comments 1 reaction 0 assignees View on GitHub
api: bigtable priority: p2 type: bug
Dominant language
Java
Stars
184
Forks
184
Avg merge
10h
Merged PRs (30d)
6

Description

Hello! Hbase's [implementation](https://github.com/apache/hbase/blob/master/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/FuzzyRowFilter.java#L117-L132) of `FuzzyRowFilter` conditionally uses either `0` or `-1` to indicate that the provided byte has a fixed value. This condition is based on whether the code can make an [illegal access](https://github.com/apache/hbase/blob/f4866a49dccdeea4a0ed73bd37f9f114fdc7ea41/hbase-common/src/main/java/org/apache/hadoop/hbase/util/UnsafeAvailChecker.java#L152-L162).

In Java 17, the `illegal-access` flag is [obsolete](https://www.oracle.com/java/technologies/javase/17-relnote-issues.html#JDK-8266851), and so it is impossible to make an illegal access, so `UNSAFE_UNALIGNED` is always `false`. This means that Hbase produces fuzzy row filters with `0` to indicate that the provided byte has a fixed value, not `-1`.

However, the FuzzyRowFilterAdapter is only checking for `-1`, not conditionally `0` in fuzzy row filters:
https://github.com/googleapis/java-bigtable-hbase/blob/main/bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/adapters/filters/FuzzyRowFilterAdapter.java#L70-L85
```
for (int i = 0; i < mask.length; i++) {
if (mask[i] == -1) {
quotingStream.write(key[i]);
} else {
// Write unquoted to match any byte at this position:
output.write(ReaderExpressionHelper.ANY_BYTE_BYTES);
}
}
```

I believe it should instead check the value of `HBasePlatformDependent.unaligned()`:
```
for (int i = 0; i < mask.length; i++) {
if (mask[i] == UnsafeAvailChecker.unaligned() ? -1 : 0) {
quotingStream.write(key[i]);
} else {
// Write unquoted to match any byte at this position:
output.write(ReaderExpressionHelper.ANY_BYTE_BYTES);
}
}
```

#### Environment details

Java version: Java 16, trying to upgrade to Java 17.

#### Steps to reproduce

1. Product an HBase fuzzy filter in Java 17, or in Java 16 with `--illegal-access=deny`
2. Pass this fuzzy filter to bigtable and check that if it is adapted correctly

#### External references such as API reference guides

See links above

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.