@@ -103,35 +103,44 @@ class HeapSegmentGuard {
103103
104104 @ Test
105105 void compressRejectsHeapSource () {
106- // Given a heap-backed segment (not off-heap) handed to the zero-copy API
107- MemorySegment heap = MemorySegment .ofArray (new byte [64 ]);
108106 try (Arena arena = Arena .ofConfined ();
109- ZstdCompressCtx cctx = new ZstdCompressCtx ()) {
107+ ZstdCompressCtx sut = new ZstdCompressCtx ()) {
108+ // Given a heap-backed source segment handed to the zero-copy API
109+ MemorySegment heapSrc = MemorySegment .ofArray (new byte [64 ]);
110110 MemorySegment dst = arena .allocate (64 );
111111
112+ // When compressing from it
112113 // Then it fails fast with a clear message instead of a cryptic FFM error
113- assertThatThrownBy (() -> cctx .compress (dst , heap ))
114+ assertThatThrownBy (() -> sut .compress (dst , heapSrc ))
114115 .isInstanceOf (IllegalArgumentException .class )
115116 .hasMessageContaining ("native" );
116117 }
117118 }
118119
119120 @ Test
120121 void decompressRejectsHeapDestination () {
121- MemorySegment heapDst = MemorySegment .ofArray (new byte [64 ]);
122122 try (Arena arena = Arena .ofConfined ();
123- ZstdDecompressCtx dctx = new ZstdDecompressCtx ()) {
123+ ZstdDecompressCtx sut = new ZstdDecompressCtx ()) {
124+ // Given a heap-backed destination segment handed to the zero-copy API
125+ MemorySegment heapDst = MemorySegment .ofArray (new byte [64 ]);
124126 MemorySegment src = arena .allocate (64 );
125127
126- assertThatThrownBy (() -> dctx .decompress (heapDst , src ))
128+ // When decompressing into it
129+ // Then it fails fast with a clear message instead of a cryptic FFM error
130+ assertThatThrownBy (() -> sut .decompress (heapDst , src ))
127131 .isInstanceOf (IllegalArgumentException .class )
128132 .hasMessageContaining ("native" );
129133 }
130134 }
131135
132136 @ Test
133137 void decompressedSizeRejectsHeapFrame () {
134- assertThatThrownBy (() -> Zstd .decompressedSize (MemorySegment .ofArray (new byte [8 ])))
138+ // Given a heap-backed frame segment
139+ MemorySegment heapFrame = MemorySegment .ofArray (new byte [8 ]);
140+
141+ // When reading its decompressed size
142+ // Then it fails fast with a clear message instead of a cryptic FFM error
143+ assertThatThrownBy (() -> Zstd .decompressedSize (heapFrame ))
135144 .isInstanceOf (IllegalArgumentException .class )
136145 .hasMessageContaining ("native" );
137146 }
0 commit comments