justinmclean opened a new issue, #10174:
URL: https://github.com/apache/gravitino/issues/10174
### What would you like to be improved?
POConverters.updateFilesetPOWithVersion reads Long lastVersion =
oldFilesetPO.getLastVersion(); and then executes lastVersion++ when
needUpdateVersion is true. If lastVersion is null, Java auto-unboxing triggers
a NullPointerException.
### How should we improve?
Handle nullable version state before incrementing. In
updateFilesetPOWithVersion, validate oldFilesetPO.getLastVersion() and either:
- throw a clear exception before incrementing, or
- normalize null to a safe baseline version (for example INIT_VERSION)
before incrementing.
Here's a unit test to help:
```
@Test
public void testUpdateFilesetPOVersionWithNullLastVersion() throws Exception
{
FilesetEntity filesetEntity =
createFileset(
1L,
"test",
NamespaceUtil.ofFileset("test_metalake", "test_catalog",
"test_schema"),
"this is test",
"hdfs://localhost/test",
ImmutableMap.of("key", "value"));
FilesetPO.Builder builder =
FilesetPO.builder().withMetalakeId(1L).withCatalogId(1L).withSchemaId(1L);
FilesetPO initPO =
POConverters.initializeFilesetPOWithVersion(filesetEntity, builder);
Field lastVersionField = FilesetPO.class.getDeclaredField("lastVersion");
lastVersionField.setAccessible(true);
lastVersionField.set(initPO, null);
Assertions.assertDoesNotThrow(
() -> POConverters.updateFilesetPOWithVersion(initPO, filesetEntity,
true));
}
```
--
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]