Repository navigation
fix(graalvm): support ValidateBodyMiddleware in native image - #155
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ValidateBodyMiddlewarecallsValidation.buildDefaultValidatorFactory()programmatically, but the GraalVM reachability metadata entry forHibernateValidatoris gated onValidationBootstrapParameters— never reachable in this code path — causingNoClassDefFoundErrorat runtimeHibernateValidatorunconditionally inreflect-config.jsonmakes it reachable, which activates 230+ValidatorImpl-conditioned entries in the reachability metadata automaticallyhibernate-validator+expresslyas runtime deps and enabledmetadataRepositoryin native-maven-pluginTodoForm(@NotNull @Size title) andPOST /todos/validateendpoint as the acceptance criteria demoTest plan
mvn test -pl kotowari-graalvm-example -am -DexcludedGroups=integrationpassesmvn -pl kotowari-graalvm-example -Pnative packagebuilds successfullycurl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{"title":"Buy milk"}'→ 200curl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{}'→ 400curl -X POST http://localhost:3000/todos/validate -H 'Content-Type: application/json' -d '{"title":""}'→ 400Closes #149
🤖 Generated with Claude Code