8000 fix(graalvm): support ValidateBodyMiddleware in native image by kawasima · Pull Request #155 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content

fix(graalvm): support ValidateBodyMiddleware in native image - #155

Merged
kawasima merged 1 commit into
developfrom
feature/graalvm-validation-support
Apr 4, 2026
Merged

kawasima merged 1 commit into
developfrom
feature/graalvm-validation-support

Conversation

@kawasima
@kawasima kawasima commented Apr 4, 2026
Copy link
Copy Markdown
Collaborator

Summary

  • ValidateBodyMiddleware calls Validation.buildDefaultValidatorFactory() programmatically, but the GraalVM reachability metadata entry for HibernateValidator is gated on ValidationBootstrapParameters — never reachable in this code path — causing NoClassDefFoundError at runtime
  • Registering HibernateValidator unconditionally in reflect-config.json makes it reachable, which activates 230+ ValidatorImpl-conditioned entries in the reachability metadata automatically
  • Added hibernate-validator + expressly as runtime deps and enabled metadataRepository in native-maven-plugin
  • Added TodoForm (@NotNull @Size title) and POST /todos/validate endpoint as the acceptance criteria demo

Test plan

  • mvn test -pl kotowari-graalvm-example -am -DexcludedGroups=integration passes
  • (if GraalVM available) mvn -pl kotowari-graalvm-example -Pnative package builds successfully
  • curl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{"title":"Buy milk"}' → 200
  • curl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{}' → 400
  • curl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{"title":""}' → 400

Closes #149

🤖 Generated with Claude Code

…149)

Hibernate Validator 9.1.0.Final ships no native-image config, and the
GraalVM reachability metadata entry for HibernateValidator is gated on
ValidationBootstrapParameters being reachable — a class never touched by
programmatic Validation.buildDefaultValidatorFactory(). This causes
NoClassDefFoundError at runtime in native image.

Fix:
- Register HibernateValidator unconditionally in reflect-config.json to
  make it reachable, which in turn activates 230+ ValidatorImpl-gated
  entries in the reachability metadata (NotNullValidator, SizeValidators, etc.)
- Enable metadataRepository in native-maven-plugin to apply Hibernate
  Validator reachability metadata automatically
- Add hibernate-validator and expressly (EL provider) as runtime deps
- Add TodoForm (@NotNull @SiZe title) and POST /todos/validate endpoint
  to demonstrate validation in native image

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kawasima
kawasima merged commit e8974b7 into develop Apr 4, 2026
1 check passed
@kawasima
kawasima deleted the feature/graalvm-validation-support branch April 4, 2026 04:28
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.

1 participant

0