[code-reflection] RFR: Fails if code model was compiled by a feature version different from the current
Paul Sandoz
psandoz at openjdk.org
Mon Dec 8 20:48:31 UTC 2025
On Mon, 8 Dec 2025 19:32:49 GMT, Mourad Abbay <mabbay at openjdk.org> wrote:
> Before we build a code model, we check if the Java feature version used to compile the code model matches the current one. In case there's no match, we throw an exception.
src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java line 5268:
> 5266: }
> 5267:
> 5268: /**
Retain the declaration order pattern as for the other methods, the var args method occurs before the list method.
src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/OpBuilder.java line 440:
> 438: InvokeOp.InvokeKind.STATIC, true,
> 439: J_L_STRING, STRING_FORMAT,
> 440: t.op(constant(J_L_STRING, "Code model was compiled with java version %d, but the actual version is %d")),
You can embed the expected runtime version directly in the string, there is no need to pass it a runtime. Then you can simplify further by using the string concat operation to directly concatenate the string and actual version.
Suggest a string of:
"The Java version used at compile time to generate and store the code model, Java " + expectedVersion + ", is not the same as the Java version used at runtime to load the code model, Java "
src/jdk.incubator.code/share/classes/jdk/incubator/code/internal/OpBuilder.java line 444:
> 442: ));
> 443: t.op(throw_(
> 444: t.op(new_(MethodRef.constructor(IllegalStateException.class, String.class), errMessage))
Throw `UnsupportedOperationException`, and then document the throwing of that by `Op.ofMethod` and `Op.ofQuotable`.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/738#discussion_r2600001606
PR Review Comment: https://git.openjdk.org/babylon/pull/738#discussion_r2600068243
PR Review Comment: https://git.openjdk.org/babylon/pull/738#discussion_r2600061141
More information about the babylon-dev
mailing list