On Wed, 22 Jul 2026 16:53:37 GMT, Jorn Vernee <[email protected]> wrote:

> Copied from the JBS issue:
> 
> While converting these tests to use JUnit instead of TestNG, I noticed some 
> false positives in the following tests:
> 
> - `TestByteBuffer::testMapCustomPath` tries to provoke an 
> `UnsupportedOperationException` when calling `FileChannel::map`, but instead 
> causes one when opening the file channel.
> 
> - `TestFunctionDescriptor::testBadCarrierMethodType` looks for an 
> `IllegalArgumentException` when calling `FunctionDescriptor::toMethodType`, 
> but this method is no longer specified to throw that exception. The exception 
> instead occurs when creating the function descriptor itself.
> 
> - `testBadSequenceElementAlignmentTooBig` and `testBadStruct` in 
> `TestLayouts` try to provoke exceptions when using hyper-aligned layouts, but 
> instead trigger exceptions when using an alignment that is not a power of 2 
> in some cases.
> 
> - `TestMemoryAlignment::testUnalignedAccess` tries to provoke an exception on 
> unaligned access, but the exception is instead thrown when creating the 
> layout upfront.
> 
> - `TestSpliterator::testHyperAligned` tries to provoke an exception when 
> calling `MemorySegments::elements` with a layout that isn't aligned for that 
> segment, but instead fails when creating the layout. 
> 
> I've switched some of these to use `assertThrows` instead of 
> `expectedException`, since that can be used to more precisely check that a 
> particular line throws an exception.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

test/jdk/java/foreign/TestFunctionDescriptor.java line 125:

> 123:                 MemoryLayout.structLayout(C_INT, C_INT),
> 124:                 MemoryLayout.sequenceLayout(3, C_INT),
> 125:                 MemoryLayout.paddingLayout(4));

We already have tests that test this for FunctionDescriptor, so this one isn't 
needed.

test/jdk/java/foreign/TestLayouts.java line 359:

> 357:     @Test(expectedExceptions = IllegalArgumentException.class)
> 358:     public void testSequenceElement() {
> 359:         SequenceLayout layout = MemoryLayout.sequenceLayout(10, 
> JAVA_INT);

Noticed this redundant line nearby as well, removed it.

test/jdk/java/foreign/TestMemoryAlignment.java line 92:

> 90:             assertNotEquals(align, 8); //if align != 8, access is always 
> unaligned
> 91:         }
> 92:     }

This kind of access error is no longer possible if the right layout is used to 
access the field, since the layout factory now already checks the alignment is 
correct.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/32014#discussion_r3632166325
PR Review Comment: https://git.openjdk.org/jdk/pull/32014#discussion_r3632170591
PR Review Comment: https://git.openjdk.org/jdk/pull/32014#discussion_r3632175764

Reply via email to