Description
Hi,
First of all, I would like to apologize for that the issue #333 I posted was incorrect.
I have once again confirmed my program behavior, so let me ask a question again.
I tried to execute cel expression against a map in DynamicMessage built with a Descriptor which created from FileDescriptorSet at run time, and then that java process resulted into dev.cel.runtime.CelEvaluationException
.
The exception message is like bellow.
Unexpected exception thrown: dev.cel.runtime.CelEvaluationException: evaluation error at <input>:8: class com.google.protobuf.DynamicMessage cannot be cast to class com.google.protobuf.MapEntry (com.google.protobuf.DynamicMessage and com.google.protobuf.MapEntry are in unnamed module of loader 'app')
My question is that are there any way to execute a cel expression to map in DynamicMessage built with a Descriptor created at run time or are there any plan to support that case in cel-java.
Description
It seems that cel-java try to convert input DynamicMessage to a generated Message, probably a Message class generated from protobuf definition, with DynamicProto::maybeAdaptDynamicMessage but when build a Descriptor from FileDescriptorSet and use it to construct DynamicMessage to pass to eval method's argument, cel-java can not load a generated Message and so use DynamicMessage::Builder as maybeBuilder that is local variable in maybeAdaptDynamicMessge.
I'm not familiar with the DynamicMessage implementation, but from the behavior it appears that DynamicMessage::Builder treats the map field as a list of DynamicMessages, then the map field in Message returned by maybeAdaptDynamicMessage will also be the list of DynamicMessages and cause exception of class cast.
If use a generated Message's Builder to build Message or use generated Message's Descriptor to build DynamicMessage and pass it to eval method as argument, cel-java will be able to acquire a generated Message's Builder at DynamicProto::maybeAdaptDynamicMessage method and it treat map field as Map, so Exception will not happen.
To Reproduce
To reproduce, create descriptor and execute cel expression with following steps.
- define protobuf message and convert it to FileDescriptorSet format using protoc as preparation
- load the FileDescriptorSet and build a Descriptor from it in java code
- build CelRuntime::Program using the Descriptor created in step 2
- create DynamicMessage::Builder with the Descriptor which generated in step 2, and parse json to DynamicMessage
- call CelRuntime.Program::eval and pass DynamicMessage built at step4
- Exception will be raised
To do that, I write test code and put here.