Skip to content

[Feature] Support evaluating dynamic messages with dynamic descriptors #350

Closed
@Kmotiko

Description

@Kmotiko

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.

  1. define protobuf message and convert it to FileDescriptorSet format using protoc as preparation
  2. load the FileDescriptorSet and build a Descriptor from it in java code
  3. build CelRuntime::Program using the Descriptor created in step 2
  4. create DynamicMessage::Builder with the Descriptor which generated in step 2, and parse json to DynamicMessage
  5. call CelRuntime.Program::eval and pass DynamicMessage built at step4
  6. Exception will be raised

To do that, I write test code and put here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions