Skip to content

quality: thread-safety docs, null validation, shared sentinels#22

Merged
dfa1 merged 1 commit into
mainfrom
quality/inspection-followups
Jun 26, 2026
Merged

quality: thread-safety docs, null validation, shared sentinels#22
dfa1 merged 1 commit into
mainfrom
quality/inspection-followups

Conversation

@dfa1

@dfa1 dfa1 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Code-quality inspection follow-ups (#2#4; #1 defensive copy is in #21).

#2 Thread-safety docs

  • ZstdInputStream / ZstdOutputStream / ZstdCompressStream / ZstdDecompressStream: documented not thread-safe (confine to one thread) — same hazard the ctx classes already document.
  • ZstdCompressDict / ZstdDecompressDict: documented immutable and safe to share across threads (the digested dictionary is read-only), since users pool them.

#3 Null validation

Fail fast with a named NullPointerException instead of an opaque NPE deep in native code:

  • requireNative now requireNonNulls first → covers every public MemorySegment entry point.
  • Objects.requireNonNull on the public byte[] / ZstdDictionary / List<byte[]> samples / stream out/in arguments across Zstd, the contexts, ZstdDictionary, the digested dicts, and the java.io streams. (Stream dictionary stays nullable = "no dictionary".)
  • Test: rejectsNullInputWithANamedMessage.

#4 Sentinel DRY

One definition of CONTENTSIZE_UNKNOWN (-1) / CONTENTSIZE_ERROR (-2) in Zstd, reused by ZstdFrame and ZstdFrameHeader — removes the duplicates and the CONTENT_SIZE_ERROR naming drift.

Test

./mvnw -pl zstd,integration-tests -am verify — 142 unit + 79 integration green, checkstyle + javadoc clean.

🤖 Generated with Claude Code

…tinels

Follow-ups from the code-quality inspection:

- Thread-safety docs (#2): document the four streams as not thread-safe
  (confine to one thread) and the two digested dictionaries as immutable
  and safe to share across threads.
- Null validation (#3): fail fast with a named NullPointerException on
  public byte[]/dictionary/sample/stream arguments instead of an opaque
  NPE deep in native code. requireNative now also rejects null, covering
  every MemorySegment entry point.
- Sentinel DRY (#4): one definition of CONTENTSIZE_UNKNOWN/_ERROR in Zstd,
  reused by ZstdFrame and ZstdFrameHeader (drops a duplicate and the
  CONTENT_SIZE_ERROR naming drift).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit 7dbad8e into main Jun 26, 2026
1 check passed
@dfa1 dfa1 deleted the quality/inspection-followups branch June 26, 2026 20:39
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.

1 participant