RFR: 8344942: Template-Based Testing Framework [v61]
Emanuel Peter
epeter at openjdk.org
Sat May 31 11:51:09 UTC 2025
On Fri, 30 May 2025 06:32:54 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:
>> Emanuel Peter has updated the pull request incrementally with two additional commits since the last revision:
>>
>> - Merge branch 'JDK-8344942-TemplateFramework-v3' of https://github.com/eme64/jdk into JDK-8344942-TemplateFramework-v3
>> - move verification
>
> test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 174:
>
>> 172: * <p>
>> 173: * The dollar and hashtag names must have at least one character. The first character must be a letter
>> 174: * or underscore (i.e. {@code a-zA-Z_}), the other characters can also be digits (i.e. {@code a-zA-Z0-9_}).
>
> This does not seem to be enforced:
>
> var testTemplate = Template.make(() -> body(
> """
> public class Foo {
> public static void main() {
> int $1var = 34;
> }
> }
> """
> ));
> System.out.println(testTemplate.render());
>
> Results in:
>
> public class Foo {
> public static void main() {
> int $1var = 34;
> }
> }
>
> which compiles fine. I can also change it to `$$var` which renders to `$var_1` which also compiles fine.
@chhagedorn
The current parsing/regex-ing is relatively simple. We only parse the "valid" cases, so the description above is still relevant.
Your example `$1var` is not a valid pattern, so the regex does not match, and there is no replacement. Sadly, in Java `$1var` is a valid variable name, so there is some chance that the user makes a mistake and gets tripped up by this.
If the user does a call to `let` or `$` with such a bad string `1var`, then they get a `RendererException`.
The question is this:
Should I really try to parse these "bad" patterns, just to validate them as well? All solutions I can think of are really complicated. Is it worth it? Or is it just a mistake by the user, and so the matching does not happen, and that is the users problem?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2117740333
More information about the hotspot-compiler-dev
mailing list