Repository navigation
Introduce ValidateMessage to enable alternative protobuf runtimes - #480
andrewparmet wants to merge 9 commits into
Conversation
Moves protovalidate-java's CEL setup from the deprecated standard runtime to the planner runtime. ## Notable callouts - Wire the compiler and runtime by hand rather than through `plannerCelBuilder()`. `CelRuntimeImpl` directs callers to subset the standard library via `setStandardFunctions` rather than `setStandardEnvironmentEnabled`, so the runtime drops stdlib `matches` that way while the checker continues to use `setStandardEnvironmentEnabled(false)`. This keeps `CustomOverload`'s caching `matches` replacement (cel-java#1038). - Set `CelOptions.current().enableHeterogeneousNumericComparisons(true)`, which `CelRuntimeImpl` requires. - Update `cel-java` to 0.13.1 preparing to support alternative Protobuf runtimes. ## Related work: - cel-java: 0.13.1 carries the CelValue-path fixes this work relies on (fixed32/64 treated as unsigned; FieldMask navigable as a message, cel-expr/cel-java#1074). - protovalidate-java: #480 introduces `MessageReflector` to support alternative Protobuf runtimes, which builds on this runtime change (supersedes #202). - protokt: open-toast/protokt#402 is the downstream consumer that validates protokt messages through `MessageReflector` on this planner runtime. ## Testing `./gradlew :conformance:conformance` passes.
|
@andrewparmet can you update the branch from main? |
|
@jonbodner-buf done! |
|
My biggest concern is there are no tests to validate these changes. Yes, the existing tests still pass, but nothing in the existing tests calls The exception thrown by |
Rename the MessageReflector interface to ValidateMessage, and accordingly ProtobufMessageReflector -> ProtobufValidateMessage and MessageReflectorValue -> ValidateMessageValue (with its `reflector` field/locals renamed to `message`). Also give the jvmValue UnsupportedOperationException on the message-backed Value types a descriptive message: MessageValue notes it carries the rule message and should be read via messageValue()/celValue(); the ValidateMessage-backed value notes that a getField() implementation returned a message value for a field evaluated as a scalar.
Add ValidateMessageTest, which validates through a map-backed ValidateMessage (no com.google.protobuf.Message): scalar / nested / repeated / map / repeated-message / map-message violations and their field paths, a valid message, the well-known Timestamp type, bytes, enum, unsigned (uint32), the Int32Value wrapper, a required oneof, the clear error when a message field is not backed by a ValidateMessage, and that jvmValue is unsupported on the message-backed Value types. Co-authored-by: Jon Bodner <jbodner@buf.build>
|
Pushed up some tests - thanks for the starter patch from your investigation! The existing Validator tests do indirectly call |
Exercise successful and failing boolean and string rules through an alternative runtime with native rules enabled and disabled. Document that field and element values must support jvmValue(Object.class), including nested messages.
Keep existing Validator implementations compatible through a default overload. Accept map-backed fields and integer enums, and check message emptiness through ValidateMessage while preserving explicit presence and unknown fields. Document raw and JVM value types and add public-API parity tests in a separate package. Use direct presence and oneof lookups, cache message adapters lazily, and skip zero-value adaptation unless the ignore rule requires it.
Adds a runtime-independent
ValidateMessageinterface so alternative protobuf runtimes, including protokt, can validate their messages without converting the root message tocom.google.protobuf.Message.Changes
ValidateMessageandValue.Validatorimplementations with a defaultvalidate(ValidateMessage)overload. The built-in validator supports both entry points.IGNORE_IF_ZERO_VALUEto empty messages across runtimes while preserving explicit presence and unknown fields.jvmValue(Object.class)for violation details, including message values. Evaluator paths and descriptor guards keep internal root and rule-metadata wrappers out of JVM conversion.Related work
ValidateMessagedownstream.Testing
Quiet-run timing benchmarks with native rules disabled (JDK 21, Linux x86_64), relative to the mean of two
maincontrols:The controls differed by at most 3.3%. CPU samples recorded no steal time or swapping. Map allocations fell from about 2,162 to 1,888 bytes per validation. Benchmark results and load samples.
A focused repeated-rule check, with six JVM forks per version in balanced order, measured -0.1% time and +1.6% mean allocation. Both versions exhibited the same three allocation levels, with the PR adding 16 bytes at each level; the larger differences between individual forks also occurred on unchanged
main.