-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Description
protovalidate-java does not register CEL string extension functions. Rules using substring() or lastIndexOf() compile and validate in protovalidate-go but fail at runtime in Java with undeclared reference.
Steps to Reproduce
- Define a message with a CEL rule that uses
substring()orlastIndexOf():
syntax = "proto3";
package test.v1;
import "buf/validate/validate.proto";
message CreateRequest {
string parent = 1;
string path = 2;
option (buf.validate.message).cel = {
id: "path_matches_parent"
message: "path must be a child of parent"
expression:
"this.path.lastIndexOf('/') >= 0 && "
"this.path.substring(0, this.path.lastIndexOf('/')) == this.parent"
};
}- Validate a
CreateRequestinstance usingprotovalidate-java.
Expected Behavior
The CEL rule compiles and validates the message, matching the behavior of protovalidate-go.
Actual Behavior
Validation fails during CEL compilation:
ERROR: <input>:1:12: undeclared reference to 'lastIndexOf' (in container '')
| this.path.lastIndexOf('/') >= 0 && this.path.substring(0, this.path.lastIndexOf('/')) == this.parent
| ...........^
ERROR: <input>:1:46: undeclared reference to 'substring' (in container '')
| this.path.lastIndexOf('/') >= 0 && this.path.substring(0, this.path.lastIndexOf('/')) == this.parent
| .............................................^
Environment
- Operating System: macOS
- Compiler/Toolchain: JDK 25 (Temurin 25.0.2), Kotlin/JVM, gRPC
- Protobuf Compiler & Version: buf
- Protovalidate Version:
build.buf:protovalidate:1.1.1
Possible Solution
ValidatorImpl.java builds the CEL environment without registering string extensions:
CelFactory.standardCelBuilder()
.addCompilerLibraries(validateLibrary)
.addRuntimeLibraries(validateLibrary)cel-java already provides SUBSTRING and LAST_INDEX_OF via CelExtensions.strings(). Registering that library in the validator's CEL environment should fix this.
Additional Context
The same schema validates correctly in Go. The issue appears to be that protovalidate-java does not enable the cel-java string extension library, not that the Java CEL runtime lacks the capability.