Skip to content

[GenAI] 4 increase graalvm native image test coverage - #136

Merged
ddekany merged 3 commits into
apache:2.3-gaefrom
fugerit-org:4-increase-graalvm-native-image-test-coverage
Nov 25, 2026
Merged

ddekany merged 3 commits into
apache:2.3-gaefrom
fugerit-org:4-increase-graalvm-native-image-test-coverage

Conversation

@fugerit79

Copy link
Copy Markdown
Contributor

Following the PR on graalvm-reachability-metadata to add Apache FreeMarker to the list of supported libraries, it was noted that:

"fully-tested means the library is fully tested for each released version. The native test in FreeMarker's CI is a single hello-world template (freemarker-test-graalvm-native), built on GraalVM 21, which is partial coverage, so please use community-tested. If FreeMarker's CI later runs a substantial part of its test suite as a native image, fully-tested will fit."

This PR is linked to FREEMARKER-229 and aims to significantly increase GraalVM Native Image test coverage for Apache FreeMarker:

  • Fix invalid .java suffixes in freemarker-core's META-INF/native-image/org.freemarker/freemarker/reflect-config.json
  • Expand freemarker-test-graalvm-native with a 17-test JUnit 5 native suite covering core directives, ranges/slicing, variadic/recursive macros and functions, built-ins, lambdas, dynamic evaluation (?eval, ?eval_json, ?interpret), BeansWrapper (Java records, enums, static models, overloaded methods, default/whitelist/blacklist/legacy member access policies), template loaders (#include, #import, auto_include, auto_import), TemplateConfiguration matchers, output formats, custom directives/methods, custom number/date formats, arithmetic engines, exception handlers, XML DOM NodeModel, Properties-based configuration, and logger resolution
  • Run :freemarker-test-graalvm-native:nativeTest in the GitHub Actions CI workflow

A preview run of the PR has already been executed here: https://github.com/fugerit-org/freemarker/actions/runs/41204979908

Note: Generative AI (Google Antigravity / Gemini) assistance was used only for the isolated freemarker-test-graalvm-native test project (and CI/README updates), reviewed and refined by the author, and not used on the FreeMarker library code itself. All the contributions have been reviewed and refined by the author.

@fugerit79

Copy link
Copy Markdown
Contributor Author

@ddekany when you have some time can we discuss this PR? as stated it only improves the test coverage for native support and does not change the codebase itself.

@ddekany

ddekany commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

I haven't reviewed it yet, but I will eventually. But if you want to ask/tell something specific, go ahead of course.

…st in CI

- Expand HelloFreeMarkerTest with JUnit 5 test scenarios covering core
  directives, built-ins, lambdas, dynamic evaluation (?eval, ?eval_json,
  ?interpret), Java records, enums, static models, overloaded methods,
  member access policies, template loaders, output formats, custom
  directives/methods, and Properties-based configuration
- Add template resources (features-suite.ftlh, included-header.ftlh,
  macro-lib.ftlh) and data model members to test #include, #import,
  macros, and functions in native image
- Run :freemarker-test-graalvm-native:nativeTest in GitHub Actions CI
  workflow and document it in README.md

Note: Generative AI (Google Gemini) assistance was used only for the isolated
freemarker-test-graalvm-native test project, reviewed and refined by the author,
and not used on the FreeMarker library code itself.
chore: updating ubuntu arm version to ubuntu 26.04

Following public preview actions/runner-images#14226 ubuntu 26 will substitute ubuntu 24 as latest tag too
@fugerit79
fugerit79 force-pushed the 4-increase-graalvm-native-image-test-coverage branch from fe53e34 to 8af69a8 Compare November 7, 2026 22:09
@fugerit79

Copy link
Copy Markdown
Contributor Author

@ddekany basically this PR does not change the code base, as you can see from the file changed :

https://github.com/apache/freemarker/pull/136/changes

The PR only improve testing of Apache FreeMarker native usage, the only other modification is :

  • fix in reflect-config.json file

Additionally I switched the ubuntu arm version from 24 to 26, following the :

All has already been tested on the fork https://github.com/fugerit-org/freemarker/actions/runs/42419285594 repository.

@ddekany

ddekany commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What should we tell albot the fixes in freemarker-core/src/main/resources/META-INF/native-image/org.freemarker/freemarker/reflect-config.json? Did it not work before that, or it was tolerated by Graal?

@ddekany
ddekany merged commit 88b77a2 into apache:2.3-gae Nov 25, 2026
3 checks passed
@ddekany

ddekany commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

I have merged it. But please tell what should go into the changelog, because of the reflect-config.json changes.

@fugerit79

Copy link
Copy Markdown
Contributor Author

@ddekany thanks, something like "Fixed invalid .java suffixes on non-SLF4J freemarker.log class names in GraalVM native reflect-config.json (introduced in 2.3.35)." could be ok?

@ddekany

ddekany commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

I mean what actuall effect does it have? In 2.3.35 Graal just ignored all those classes, and they were unaccessible via reflection (if you have used AOC of course)? I'm just surprised that Graal compilation did not fail then. Then it seems we need to cover accessing every such entry via getClass/getResource/reflection in the JUnit tests...

@fugerit79

fugerit79 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor Author

I mean what actuall effect does it have? In 2.3.35 Graal just ignored all those classes, and they were unaccessible via reflection (if you have used AOC of course)? I'm just surprised that Graal compilation did not fail then. Then it seems we need to cover accessing every such entry via getClass/getResource/reflection in the JUnit tests...

Right: in 2.3.35 those .java-suffixed entries were effectively ignored, so the factory classes weren't registered for reflection (native-image doesn't fail on entries for classes it can't resolve). Only native-image users were affected.

Concretely, in Logger:

  • JUL and None are created with new, so they were unaffected. (so no entry in reflect-config was actually needed)
  • SLF4J's entries were correct, and it's tried first under native, so SLF4J users never saw an issue.
  • For Commons Logging, Log4j, and Avalon, Class.forName("freemarker.log._<Name>LoggerFactory") failed. In auto-detection, Logger printed an "Unexpected error when initializing logging" message to stderr and fell through to the next library (typically JUL). With -Dorg.freemarker.loggerLibrary set explicitly, logging ended up disabled. So not a crash, but the wrong logger or no logging.

Changelog suggestion:

Fixed GraalVM native-image reflect-config.json (2.3.35): freemarker.log factory classes for Commons Logging, Log4j, and Avalon had an invalid .java suffix, so they weren't registered for reflection. In native images, FreeMarker then printed an error and fell back to another logger (typically JUL), or disabled logging if the library was selected via org.freemarker.loggerLibrary.

Agreed on tests. I'd add a JUnit test verifying that every class in reflect-config.json resolves (third-party classes only when on the classpath), the same for resource-config.json via getResource, and a nativeTest that verifies runtime access to the configured classes (with the relevant optional logging dependencies on the native test classpath) and resources. I can open a follow-up PR.

I hope this covers everything — sorry for missing those .java suffixes earlier!

@fugerit79
fugerit79 deleted the 4-increase-graalvm-native-image-test-coverage branch November 26, 2026 14:34
@ddekany

ddekany commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Thanks, I pushed the version history update accordingly.

If Graal doesn't have any option to validate the JSON-s (weird...), then we have to validate their contents in a JUnit test ourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants