HotSushi opened a new pull request, #4446:
URL: https://github.com/apache/polaris/pull/4446
## Summary
The `PolarisBaseEntity.Builder` constructor contained a silent 0→1 coercion
for `grantRecordsVersion`:
```java
// Before (buggy)
this.grantRecordsVersion = builder.grantRecordsVersion == 0 ? 1 :
builder.grantRecordsVersion;
// After (fixed)
this.grantRecordsVersion = builder.grantRecordsVersion;
```
When an entity with a legitimate `grantRecordsVersion=0` was deserialized
via the Builder (e.g. from a `ResolvedEntityResult` JSON response), the
entity's version was silently bumped to 1 while the companion top-level
`grantRecordsVersion` in `ResolvedEntityResult` remained 0. This caused
`ResolvedPolarisEntity` to crash with `grants_version_going_backward` because
the invariant check `entity.getGrantRecordsVersion() <= grantsVersion`
evaluated to `1 <= 0 = false`.
### Root cause
A `PRINCIPAL_ROLE` entity that has never had its grants modified has
`grantRecordsVersion=0` in the backing store. The Builder's 0→1 guard was
originally intended to initialize _new_ entities at version 1, but new entities
are already correctly initialized to 1 via the explicit constructors. The
Builder guard instead corrupts the version during deserialization of any entity
whose stored value is 0.
### What changed
- **`PolarisBaseEntity.java`**: Removed the `== 0 ? 1` guard from the
`Builder`-based constructor so that `grantRecordsVersion=0` is faithfully
preserved.
- **`PolarisBaseEntityTest.java`** (new): Regression tests that verify:
- `Builder` preserves `grantRecordsVersion=0`
- `ResolvedPolarisEntity` constructs successfully when
`entity.grantRecordsVersion == grantsVersion == 0`
- Non-zero values are preserved
- `withGrantRecordsVersion(0)` works correctly
### No behavior change for new entities
Entities created via the explicit constructors (`new
PolarisBaseEntity(catalogId, id, type, ...)`) continue to initialize
`grantRecordsVersion` to 1 as before (line 263). Only the Builder path is
affected.
Made with [Cursor](https://cursor.com)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]