sdj3261 opened a new pull request, #7986:
URL: https://github.com/apache/gravitino/pull/7986
### What changes were proposed in this pull request?
Namespace constructor parameter is an array, So apply defensive copying to
ensure immutability and add test code.
### Why are the changes needed?
Previously, modifying the input array externally could affect the internal
state of Namespace.
The levels() method also exposed the internal array, allowing unintended
external mutations.
Fix: #7957
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
```
@Test
public void testNamespaceImmutability() {
String[] levels = new String[] {"a", "b"};
Namespace ns = Namespace.of(levels);
// Modifying the original array should not affect the namespace
levels[0] = "x";
Assertions.assertEquals("a", ns.level(0));
// Modifications to the returned levels array should also not affect the
namespace
String[] returnedLevels = ns.levels();
returnedLevels[1] = "y";
Assertions.assertEquals("b", ns.level(1));
}
```
--
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]