Skip to content

Fix native library loading failure due to buffer comparison bug#318

Merged
gnodet merged 1 commit intomasterfrom
fix-contentsEquals-buffer-comparison
Mar 27, 2026
Merged

Fix native library loading failure due to buffer comparison bug#318
gnodet merged 1 commit intomasterfrom
fix-contentsEquals-buffer-comparison

Conversation

@gnodet
Copy link
Copy Markdown
Member

@gnodet gnodet commented Mar 27, 2026

Summary

  • Fix contentsEquals() in JansiLoader to compare only the bytes actually read from each stream, instead of comparing the entire 8192-byte buffer via Arrays.equals()
  • On the final chunk of a stream, bytes beyond the read count contain stale data from the previous iteration, causing a false "Content differs" mismatch that prevents the native library from loading
  • Uses a JDK 8-compatible byte-by-byte loop instead of the JDK 9+ Arrays.equals(byte[], int, int, byte[], int, int) overload

Fixes #317

Test plan

  • Verified the project compiles successfully
  • Test on JDK 21 + Fedora/Linux to confirm native library loads and ANSI color output works
  • Test on JDK 8 to confirm backwards compatibility

🤖 Generated with Claude Code

Claude Code on behalf of Guillaume Nodet

…son (#317)

Compare only the bytes actually read from each stream instead of the
entire 8192-byte buffer in contentsEquals(). When the final chunk is
smaller than the buffer, stale bytes from the previous iteration could
cause a false mismatch, preventing the native library from loading.

Uses a byte-by-byte loop instead of Arrays.equals() to maintain JDK 8
compatibility.

Fixes #317

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet merged commit 300aa78 into master Mar 27, 2026
6 checks passed
@gnodet gnodet deleted the fix-contentsEquals-buffer-comparison branch March 27, 2026 12:23
sarutak pushed a commit to apache/spark that referenced this pull request Apr 18, 2026
### What changes were proposed in this pull request?

This PR upgrades `Maven` to 3.9.15.

### Why are the changes needed?

To use the latest Maven version.
- https://maven.apache.org/docs/3.9.15/release-notes.html
  - apache/maven#11876
    - codehaus-plexus/plexus-utils#304
  - apache/maven#11865
    - fusesource/jansi#318
    - fusesource/jansi#317
- https://github.com/apache/maven/releases/tag/maven-3.9.15

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Pass the CIs and check the log.
- https://github.com/dongjoon-hyun/spark/actions/runs/24586452868/job/71897297495

```
Using `mvn` from path: /home/runner/work/spark/spark/build/apache-maven-3.9.15/bin/mvn
```

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (claude-opus-4-7)

Closes #55398 from dongjoon-hyun/SPARK-56530.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: Kousuke Saruta <sarutak@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No color output in Fedora and JDK21

1 participant