Skip to content

Commit 83d3436

Browse files
dfa1claude
andcommitted
test: sweep remaining local LE layout constants to PTypeIO.LE_*
Twelve array/security tests each declared their own ValueLayout.JAVA_*_UNALIGNED.withOrder(LITTLE_ENDIAN) constant (variously named LE_INT, LONG_LE, leDouble, …) duplicating the public PTypeIO.LE_*. Replace all with PTypeIO.LE_* and drop the now-unused ValueLayout/ByteOrder imports. No behaviour change: core+reader+writer unit suites green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e767842 commit 83d3436

12 files changed

Lines changed: 42 additions & 84 deletions

reader/src/test/java/io/github/dfa1/vortex/reader/FlatSegmentBoundsSecurityTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.dfa1.vortex.reader;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import com.google.flatbuffers.FlatBufferBuilder;
45
import io.github.dfa1.vortex.core.DType;
56
import io.github.dfa1.vortex.core.PType;
@@ -11,8 +12,6 @@
1112

1213
import java.lang.foreign.Arena;
1314
import java.lang.foreign.MemorySegment;
14-
import java.lang.foreign.ValueLayout;
15-
import java.nio.ByteOrder;
1615
import java.util.List;
1716

1817
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -25,8 +24,6 @@
2524
/// a [VortexException], never a raw `IndexOutOfBoundsException` from `MemorySegment.asSlice`.
2625
class FlatSegmentBoundsSecurityTest {
2726

28-
private static final ValueLayout.OfInt LE_INT =
29-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
3027

3128
private static final DType DTYPE = new DType.Primitive(PType.I32, false);
3229

@@ -50,7 +47,7 @@ void declaredFbLenLargerThanSegment_throwsVortexException() {
5047
// Given a 16-byte segment whose trailing u32 claims a 1 000 000-byte FlatBuffer;
5148
// fbStart = segLen - 4 - fbLen would go deeply negative.
5249
MemorySegment seg = arena.allocate(16);
53-
seg.set(LE_INT, 12, 1_000_000);
50+
seg.set(PTypeIO.LE_INT, 12, 1_000_000);
5451

5552
// When / Then
5653
assertThatThrownBy(() -> sut.decode(seg, List.of("vortex.flat"), DTYPE, 1, arena))
@@ -63,7 +60,7 @@ void negativeFbLen_throwsVortexException() {
6360
try (Arena arena = Arena.ofConfined()) {
6461
// Given a trailing u32 of 0xFFFFFFFF — reads back as a signed int of -1
6562
MemorySegment seg = arena.allocate(16);
66-
seg.set(LE_INT, 12, -1);
63+
seg.set(PTypeIO.LE_INT, 12, -1);
6764

6865
// When / Then the negative length is rejected (checkRange len < 0)
6966
assertThatThrownBy(() -> sut.decode(seg, List.of("vortex.flat"), DTYPE, 1, arena))
@@ -79,7 +76,7 @@ void bufferDescriptorLengthPastSegment_throwsVortexException() {
7976
byte[] fb = arrayFlatBufferWithOneBuffer(1_000_000L);
8077
MemorySegment seg = arena.allocate(fb.length + 4L);
8178
MemorySegment.copy(MemorySegment.ofArray(fb), 0, seg, 0, fb.length);
82-
seg.set(LE_INT, fb.length, fb.length);
79+
seg.set(PTypeIO.LE_INT, fb.length, fb.length);
8380

8481
// When / Then the buffer slice is bounds-checked before asSlice
8582
assertThatThrownBy(() -> sut.decode(seg, List.of("vortex.flat"), DTYPE, 1, arena))

reader/src/test/java/io/github/dfa1/vortex/reader/array/DoubleArrayTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package io.github.dfa1.vortex.reader.array;
22

33

4+
import io.github.dfa1.vortex.encoding.PTypeIO;
45
import io.github.dfa1.vortex.core.DType;
56
import io.github.dfa1.vortex.core.PType;
67
import org.junit.jupiter.api.Nested;
78
import org.junit.jupiter.api.Test;
89

910
import java.lang.foreign.Arena;
1011
import java.lang.foreign.MemorySegment;
11-
import java.lang.foreign.ValueLayout;
12-
import java.nio.ByteOrder;
1312
import java.util.ArrayList;
1413
import java.util.List;
1514

1615
import static org.assertj.core.api.Assertions.assertThat;
1716

1817
class DoubleArrayTest {
1918

20-
private static final ValueLayout.OfDouble LE_DOUBLE =
21-
ValueLayout.JAVA_DOUBLE_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2219

2320
private static DoubleArray of(double... values) {
2421
return TestArrays.doubles(values);
@@ -70,7 +67,7 @@ void singleElement_consumerCalledOnce() {
7067
void logicalLengthExceedsCapacity_wrapsAround() {
7168
// Given — constant-encoding: 1-element buffer, logical length 3; all 3 visits yield same value
7269
MemorySegment seg = Arena.ofAuto().allocate(8, 8);
73-
seg.setAtIndex(LE_DOUBLE, 0, 2.71);
70+
seg.setAtIndex(PTypeIO.LE_DOUBLE, 0, 2.71);
7471
DoubleArray sut = new MaterializedDoubleArray(new DType.Primitive(PType.F64, false), 3, seg);
7572
List<Double> collected = new ArrayList<>();
7673

reader/src/test/java/io/github/dfa1/vortex/reader/array/IntArrayTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package io.github.dfa1.vortex.reader.array;
22

33

4+
import io.github.dfa1.vortex.encoding.PTypeIO;
45
import io.github.dfa1.vortex.core.DType;
56
import io.github.dfa1.vortex.core.PType;
67
import org.junit.jupiter.api.Nested;
78
import org.junit.jupiter.api.Test;
89

910
import java.lang.foreign.Arena;
1011
import java.lang.foreign.MemorySegment;
11-
import java.lang.foreign.ValueLayout;
12-
import java.nio.ByteOrder;
1312
import java.util.ArrayList;
1413
import java.util.List;
1514

1615
import static org.assertj.core.api.Assertions.assertThat;
1716

1817
class IntArrayTest {
1918

20-
private static final ValueLayout.OfInt LE_INT =
21-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2219

2320
private static IntArray of(int... values) {
2421
return TestArrays.ints(values);
@@ -70,7 +67,7 @@ void singleElement_consumerCalledOnce() {
7067
void logicalLengthExceedsCapacity_wrapsAround() {
7168
// Given — constant-encoding: 1-element buffer, logical length 4; all 4 visits yield same value
7269
MemorySegment seg = Arena.ofAuto().allocate(4, 4);
73-
seg.setAtIndex(LE_INT, 0, 7);
70+
seg.setAtIndex(PTypeIO.LE_INT, 0, 7);
7471
IntArray sut = new MaterializedIntArray(new DType.Primitive(PType.I32, false), 4, seg);
7572
List<Integer> collected = new ArrayList<>();
7673

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyAlpDoubleArrayTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import org.junit.jupiter.api.Nested;
67
import org.junit.jupiter.api.Test;
78

89
import java.lang.foreign.Arena;
910
import java.lang.foreign.MemorySegment;
10-
import java.lang.foreign.ValueLayout;
11-
import java.nio.ByteOrder;
1211
import java.util.ArrayList;
1312
import java.util.List;
1413

@@ -17,15 +16,13 @@
1716

1817
class LazyAlpDoubleArrayTest {
1918

20-
private static final ValueLayout.OfLong LE_LONG =
21-
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2219

2320
private static final DType F64 = new DType.Primitive(PType.F64, false);
2421

2522
private static LazyAlpDoubleArray of(double scale, long... encoded) {
2623
MemorySegment seg = Arena.ofAuto().allocate((long) encoded.length * 8, 8);
2724
for (int i = 0; i < encoded.length; i++) {
28-
seg.setAtIndex(LE_LONG, i, encoded[i]);
25+
seg.setAtIndex(PTypeIO.LE_LONG, i, encoded[i]);
2926
}
3027
return new LazyAlpDoubleArray(F64, encoded.length, seg, scale, 1.0);
3128
}
@@ -119,16 +116,14 @@ class Materialize {
119116
void decodesAllRows() {
120117
// Given
121118
LazyAlpDoubleArray sut = of(0.01, 123L, 456L, 789L);
122-
ValueLayout.OfDouble leDouble =
123-
ValueLayout.JAVA_DOUBLE_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
124119

125120
// When
126121
try (Arena arena = Arena.ofConfined()) {
127122
MemorySegment seg = sut.materialize(arena);
128123

129124
// Then — each materialized row matches the lazy getter
130125
for (int i = 0; i < 3; i++) {
131-
assertThat(seg.getAtIndex(leDouble, i)).as("row %d", i)
126+
assertThat(seg.getAtIndex(PTypeIO.LE_DOUBLE, i)).as("row %d", i)
132127
.isCloseTo(sut.getDouble(i), offset(1e-12));
133128
}
134129
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyAlpFloatArrayTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import org.junit.jupiter.api.Test;
67

78
import java.lang.foreign.Arena;
89
import java.lang.foreign.MemorySegment;
9-
import java.lang.foreign.ValueLayout;
10-
import java.nio.ByteOrder;
1110

1211
import static org.assertj.core.api.Assertions.assertThat;
1312
import static org.assertj.core.api.Assertions.offset;
1413

1514
class LazyAlpFloatArrayTest {
1615

17-
private static final ValueLayout.OfInt LE_INT =
18-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
1916

2017
private static final DType F32 = new DType.Primitive(PType.F32, false);
2118

2219
private static LazyAlpFloatArray of(float scale, int... encoded) {
2320
MemorySegment seg = Arena.ofAuto().allocate((long) encoded.length * 4, 4);
2421
for (int i = 0; i < encoded.length; i++) {
25-
seg.setAtIndex(LE_INT, i, encoded[i]);
22+
seg.setAtIndex(PTypeIO.LE_INT, i, encoded[i]);
2623
}
2724
return new LazyAlpFloatArray(F32, encoded.length, seg, scale, 1.0f);
2825
}
@@ -54,16 +51,14 @@ void foldSumApplies() {
5451
void materializeDecodesAllRows() {
5552
// Given
5653
LazyAlpFloatArray sut = of(0.01f, 123, 456, 789);
57-
ValueLayout.OfFloat leFloat =
58-
ValueLayout.JAVA_FLOAT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
5954

6055
// When
6156
try (Arena arena = Arena.ofConfined()) {
6257
MemorySegment seg = sut.materialize(arena);
6358

6459
// Then — each materialized row matches the lazy getter
6560
for (int i = 0; i < 3; i++) {
66-
assertThat(seg.getAtIndex(leFloat, i)).as("row %d", i)
61+
assertThat(seg.getAtIndex(PTypeIO.LE_FLOAT, i)).as("row %d", i)
6762
.isCloseTo(sut.getFloat(i), offset(1e-6f));
6863
}
6964
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyDecimalArrayTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import io.github.dfa1.vortex.core.VortexException;
@@ -10,29 +11,22 @@
1011
import java.lang.foreign.ValueLayout;
1112
import java.math.BigDecimal;
1213
import java.math.BigInteger;
13-
import java.nio.ByteOrder;
1414

1515
import static org.assertj.core.api.Assertions.assertThat;
1616
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1717

1818
class LazyDecimalArrayTest {
1919

20-
private static final ValueLayout.OfShort SHORT_LE =
21-
ValueLayout.JAVA_SHORT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
22-
private static final ValueLayout.OfInt INT_LE =
23-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
24-
private static final ValueLayout.OfLong LONG_LE =
25-
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2620

2721
@Test
2822
void getDecimal_i64Buffer_appliesDtypeScale() {
2923
// Given — vortex.decimal stores one LE two's-complement integer per row;
3024
// decimal(15, 2) with mantissa 4321 represents 43.21.
3125
try (Arena arena = Arena.ofConfined()) {
3226
MemorySegment buf = arena.allocate(24);
33-
buf.set(LONG_LE, 0, 4321L);
34-
buf.set(LONG_LE, 8, -100L);
35-
buf.set(LONG_LE, 16, 0L);
27+
buf.set(PTypeIO.LE_LONG, 0, 4321L);
28+
buf.set(PTypeIO.LE_LONG, 8, -100L);
29+
buf.set(PTypeIO.LE_LONG, 16, 0L);
3630
DType.Decimal dec = new DType.Decimal((byte) 15, (byte) 2, false);
3731
LazyDecimalArray sut = new LazyDecimalArray(dec, 3, buf, 8);
3832

@@ -59,16 +53,16 @@ void getDecimal_i8I16I32Widths_signExtend() {
5953
assertThat(sut1.getDecimal(1)).isEqualByComparingTo(new BigDecimal("-0.5"));
6054

6155
MemorySegment buf2 = arena.allocate(4);
62-
buf2.set(SHORT_LE, 0, (short) 1234);
63-
buf2.set(SHORT_LE, 2, (short) -7);
56+
buf2.set(PTypeIO.LE_SHORT, 0, (short) 1234);
57+
buf2.set(PTypeIO.LE_SHORT, 2, (short) -7);
6458
DType.Decimal dec2 = new DType.Decimal((byte) 4, (byte) 2, false);
6559
LazyDecimalArray sut2 = new LazyDecimalArray(dec2, 2, buf2, 2);
6660
assertThat(sut2.getDecimal(0)).isEqualByComparingTo(new BigDecimal("12.34"));
6761
assertThat(sut2.getDecimal(1)).isEqualByComparingTo(new BigDecimal("-0.07"));
6862

6963
MemorySegment buf4 = arena.allocate(8);
70-
buf4.set(INT_LE, 0, 999_999);
71-
buf4.set(INT_LE, 4, -1);
64+
buf4.set(PTypeIO.LE_INT, 0, 999_999);
65+
buf4.set(PTypeIO.LE_INT, 4, -1);
7266
DType.Decimal dec4 = new DType.Decimal((byte) 9, (byte) 3, false);
7367
LazyDecimalArray sut4 = new LazyDecimalArray(dec4, 2, buf4, 4);
7468
assertThat(sut4.getDecimal(0)).isEqualByComparingTo(new BigDecimal("999.999"));

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyForIntArrayTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import org.junit.jupiter.api.Test;
67

78
import java.lang.foreign.Arena;
89
import java.lang.foreign.MemorySegment;
9-
import java.lang.foreign.ValueLayout;
10-
import java.nio.ByteOrder;
1110
import java.util.ArrayList;
1211
import java.util.List;
1312

1413
import static org.assertj.core.api.Assertions.assertThat;
1514

1615
class LazyForIntArrayTest {
1716

18-
private static final ValueLayout.OfInt LE_INT =
19-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2017

2118
private static final DType I32 = new DType.Primitive(PType.I32, false);
2219

2320
private static LazyForIntArray of(int ref, int... encoded) {
2421
MemorySegment seg = Arena.ofAuto().allocate((long) encoded.length * 4, 4);
2522
for (int i = 0; i < encoded.length; i++) {
26-
seg.setAtIndex(LE_INT, i, encoded[i]);
23+
seg.setAtIndex(PTypeIO.LE_INT, i, encoded[i]);
2724
}
2825
return new LazyForIntArray(I32, encoded.length, seg, ref);
2926
}
@@ -75,7 +72,7 @@ void materializeDecodesAllRows() {
7572

7673
// Then — materialized rows match the lazy getter
7774
for (int i = 0; i < 3; i++) {
78-
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
75+
assertThat(seg.getAtIndex(PTypeIO.LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
7976
}
8077
}
8178
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyForLongArrayTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import org.junit.jupiter.api.Nested;
67
import org.junit.jupiter.api.Test;
78

89
import java.lang.foreign.Arena;
910
import java.lang.foreign.MemorySegment;
10-
import java.lang.foreign.ValueLayout;
11-
import java.nio.ByteOrder;
1211
import java.util.ArrayList;
1312
import java.util.List;
1413

1514
import static org.assertj.core.api.Assertions.assertThat;
1615

1716
class LazyForLongArrayTest {
1817

19-
private static final ValueLayout.OfLong LE_LONG =
20-
ValueLayout.JAVA_LONG_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2118

2219
private static final DType I64 = new DType.Primitive(PType.I64, false);
2320

2421
private static LazyForLongArray of(long ref, long... encoded) {
2522
MemorySegment seg = Arena.ofAuto().allocate((long) encoded.length * 8, 8);
2623
for (int i = 0; i < encoded.length; i++) {
27-
seg.setAtIndex(LE_LONG, i, encoded[i]);
24+
seg.setAtIndex(PTypeIO.LE_LONG, i, encoded[i]);
2825
}
2926
return new LazyForLongArray(I64, encoded.length, seg, ref);
3027
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyZigZagIntArrayTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
package io.github.dfa1.vortex.reader.array;
22

3+
import io.github.dfa1.vortex.encoding.PTypeIO;
34
import io.github.dfa1.vortex.core.DType;
45
import io.github.dfa1.vortex.core.PType;
56
import org.junit.jupiter.api.Test;
67

78
import java.lang.foreign.Arena;
89
import java.lang.foreign.MemorySegment;
9-
import java.lang.foreign.ValueLayout;
10-
import java.nio.ByteOrder;
1110
import java.util.ArrayList;
1211
import java.util.List;
1312

1413
import static org.assertj.core.api.Assertions.assertThat;
1514

1615
class LazyZigZagIntArrayTest {
1716

18-
private static final ValueLayout.OfInt LE_INT =
19-
ValueLayout.JAVA_INT_UNALIGNED.withOrder(ByteOrder.LITTLE_ENDIAN);
2017

2118
private static final DType I32 = new DType.Primitive(PType.I32, false);
2219

2320
private static LazyZigZagIntArray of(int... encoded) {
2421
MemorySegment seg = Arena.ofAuto().allocate((long) encoded.length * 4, 4);
2522
for (int i = 0; i < encoded.length; i++) {
26-
seg.setAtIndex(LE_INT, i, encoded[i]);
23+
seg.setAtIndex(PTypeIO.LE_INT, i, encoded[i]);
2724
}
2825
return new LazyZigZagIntArray(I32, encoded.length, seg);
2926
}
@@ -77,7 +74,7 @@ void materializeDecodesAllRows() {
7774

7875
// Then — materialized rows match the lazy getter
7976
for (int i = 0; i < 5; i++) {
80-
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
77+
assertThat(seg.getAtIndex(PTypeIO.LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
8178
}
8279
}
8380
}

0 commit comments

Comments
 (0)