RFR: 8357466: Create test for Ciphers that are using ByteBuffers backed by MemorySegments
Mikhail Yankelevich
myankelevich at openjdk.org
Mon Sep 1 13:12:48 UTC 2025
On Thu, 28 Aug 2025 11:41:59 GMT, Matthew Donovan <mdonovan at openjdk.org> wrote:
>> test/jdk/javax/crypto/CipherSpi/CipherByteBufferOverwriteTest.java line 127:
>>
>>> 125: System.out.println("All Tests Passed");
>>> 126: } finally {
>>> 127: arena.close();
>>
>> Would it make sense to initialize `arena` in a try-with-resources, so you can get rid of the explicit `.close()`?
>
> I considered that for a while but I couldn't see a way to make it work without completely refactoring the whole test.
Wouldn't it work if you pass arena as a param to the prepareBuffers. This way you can call try-with-resources for each test and get rid of `arena.close()`.
Also, it's only `case MEMORY_SEGMENT:` which needs arena at all, so you can just pass null to all others and only for `test#3`
// Test#3: against ByteBuffer backed by MemorySegment
try (Arena arena = Arena.ofConfined()) {
prepareBuffers(BufferType.MEMORY_SEGMENT, useRO, buf.length,
buf, 0, PLAINTEXT_SIZE, offset, arena);
runTest(offset, expectedPT, expectedCT);
System.out.println("\tMEMSEGMENT: passed");
}
all others will look like this `prepareBuffers(BufferType.ALLOCATE, useRO, buf.length, buf, 0, PLAINTEXT_SIZE, offset, null);`, making it a minor refactor, as this method is only used here.
What do you think?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26967#discussion_r2313915622
More information about the security-dev
mailing list