This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch branch-4.x
in repository https://gitbox.apache.org/repos/asf/spark.git
The following commit(s) were added to refs/heads/branch-4.x by this push:
new f177feacfe12 [SPARK-57427][CORE] Improve `UTF8String` bounds checks
with `Objects.checkIndex`
f177feacfe12 is described below
commit f177feacfe12ea91260fa5db061e1ce85e90f22f
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Sun Jun 14 08:43:35 2026 -0700
[SPARK-57427][CORE] Improve `UTF8String` bounds checks with
`Objects.checkIndex`
### What changes were proposed in this pull request?
Use `java.util.Objects.checkIndex(index, length)` (Java 9+) in place of the
hand-written `index < 0 || index >= length` bounds checks in
`UTF8String.getChar`
and `UTF8String.codePointFrom`.
### Why are the changes needed?
It replaces boilerplate with a single, intention-revealing JDK call. No
functional
change (the same `IndexOutOfBoundsException` is thrown).
Additionally, this provides a better exception message than the current
one, `new IndexOutOfBoundsException()`, in case of failure.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Pass the CIs.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 4.8)
Closes #56489 from dongjoon-hyun/SPARK-57427.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 4608e44a739e017b006c2fae16ccc0e4e96072f8)
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../src/main/java/org/apache/spark/unsafe/types/UTF8String.java | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git
a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
index 96b103ae3388..ab57e308ee4d 100644
--- a/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
+++ b/common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.function.Function;
import java.util.Iterator;
import java.util.Map;
+import java.util.Objects;
import java.util.regex.Pattern;
import com.esotericsoftware.kryo.Kryo;
@@ -711,9 +712,7 @@ public final class UTF8String implements
Comparable<UTF8String>, Externalizable,
* If `byteIndex` of the first byte in the code point is known, use
`codePointFrom` instead.
*/
public int getChar(int charIndex) {
- if (charIndex < 0 || charIndex >= numChars()) {
- throw new IndexOutOfBoundsException();
- }
+ Objects.checkIndex(charIndex, numChars());
int charCount = 0, byteCount = 0;
while (charCount < charIndex) {
byteCount += numBytesForFirstByte(getByte(byteCount));
@@ -727,9 +726,7 @@ public final class UTF8String implements
Comparable<UTF8String>, Externalizable,
* If byte index is invalid, throws exception.
*/
public int codePointFrom(int byteIndex) {
- if (byteIndex < 0 || byteIndex >= numBytes) {
- throw new IndexOutOfBoundsException();
- }
+ Objects.checkIndex(byteIndex, numBytes);
byte b = getByte(byteIndex);
int numBytes = numBytesForFirstByte(b);
return switch (numBytes) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]