RFR: 8365588: defineClass that accepts a ByteBuffer does not work as expected [v5]

Xueming Shen sherman at openjdk.org
Mon Oct 13 07:49:08 UTC 2025


On Mon, 13 Oct 2025 06:55:02 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> Just tried to make the test code less verbose / repetitive :-) Updated accordingly.
>
> Thank you, this is much better. One other thing that will simplify it further is to drop the posAtLimit parameter. Instead, testDefineClassWithCustomLoaderByteBuffer can capture the bb position and limit, then test their values after the defineClass, e.g.
> 
>         if (bb.isDirect() || bb.hasArray()) {
>             assertEquals(originalPos, bb.position());
>         } else {
>             assertEquals(originalLimit, bb.position());
>         }
>         assertEquals(originalLimit, bb.limit());
> 
> This will test long-standing (and undocumented) behavior. I created JDK-8352583 on the spec issue. It would be too risky to change behavior and advance the position. There may be some flexibility to not advance the position for the read-only buffer case, but we would need to work through the compatibility impacts of that. The fallback is to just document long standing behavior.

updated as suggested.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27569#discussion_r2425464873


More information about the core-libs-dev mailing list