[code-reflection] RFR: Test java version check we do in op building methods [v3]

Paul Sandoz psandoz at openjdk.org
Wed Dec 17 22:53:43 UTC 2025


On Wed, 17 Dec 2025 20:19:16 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:

>> Write test to make sure java version check we do before building models is working.
>> There are other options to do the test, one in particular is passing the java compile time version as option and update the OpBuilder to accept the feature version we test against.
>
> Mourad Abbay has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Test reflectable lambda
>  - Apply suggestion

test/jdk/java/lang/reflect/code/writer/TestJavaVersionChecker.java line 35:

> 33:     void test() throws ReflectiveOperationException, IOException {
> 34:         Method m = this.getClass().getDeclaredMethod("max", int.class, int.class);
> 35:         Assertions.assertThrows(UnsupportedOperationException.class, () -> Op.ofMethod(m));

What happens if you call `Op.ofMethod` again after the first failure?

test/jdk/java/lang/reflect/code/writer/TestJavaVersionChecker.java line 48:

> 46:             ie = e;
> 47:         }
> 48:         Assertions.assertNotNull(ie, "Reflectable lambda creation didn't fail as expected");

Recommend you separate out the tests for methods and lambdas.

The behavior for lambdas is an unfortunate deviation from that of methods, and it's hard to diagnose and occurs at a distance from where the quoted code model is requested. We need to be consistent, which indicates we have to revisit how we load the code model and extract the quoted code model. At the moment the code model is loaded (built) when the LMF inner class is initialized, and the quoted code model extracted when the inner class is instantiated. We should really be lazy. We might have discussed that but avoided it due to the additional complexity in an already complex area. Now we have a better understanding we can revisit. Let's do so in another PR.

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

PR Review Comment: https://git.openjdk.org/babylon/pull/748#discussion_r2628841429
PR Review Comment: https://git.openjdk.org/babylon/pull/748#discussion_r2628898871


More information about the babylon-dev mailing list