Skip to content

Correctly manage execution of invalid models #1619

Open
apache/incubator-kie-drools
#6200
@gitgabrio

Description

@gitgabrio

Inside

DMNFEELHelper#compileFeelExpression(DMNCompilerContext, String, DMNModelImpl, DMNElement, Msg.Message, Object...) {
...
        CompiledExpression ce = feel.compile( expression, feelctx );
        processEvents( model, element, errorMsg, msgParams );
        return ce;
}

a CompiledExpression is returned even in presence of Syntax errors, that are simply sent to MsgUtil.
Then, the calling code

DMNEvaluatorCompiler#compileLiteralExpression(DMNCompilerContext, DMNModelImpl, DMNBaseNode, String, LiteralExpression) {
...
CompiledExpression compiledExpression = ctx.getFeelHelper().compileFeelExpression(ctx,
                                                                                        exprText,
                                                                                        model,
                                                                                        expression,
                                                                                    Msg.ERR_COMPILING_FEEL_EXPR_FOR_NAME_ON_NODE,
                                                                                        exprText,
                                                                                        exprName,
                                                                                        node.getIdentifierString() );
                    evaluator = new DMNLiteralExpressionEvaluator(compiledExpression, expression, ctx.getFeelHelper().newFEELInstance());
...

ignores the error messages, set the evaluator, and uses it to evaluate the model.
The result of all that is inconsistent, since

  1. on one side, the expression has syntax errors, so it should be completely discarded
  2. but on the other side, an evaluator is instantiated and fired, leading to some kind of result.

This is demonstrated by the attached DMN-Invalid.txt and the following snippet:

File modelFile = FileUtils.getFile("DMN-Invalid.dmn");
Resource modelResource = ResourceFactory.newFileResource(modelFile);
DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration()
                .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new);
String nameSpace = "https://kie.org/dmn/_C41C5BB7-C6D3-44AC-AA11-8C6669A1067C";
final DMNModel dmnModel = dmnRuntime.getModel(
                nameSpace,
                "DMN_9A35369C-E843-446F-A720-2A41B827FB8D");
final DMNContext context = DMNFactory.newContext();
context.set( "Person Age", 24 );
final DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context );

Result

DMNResultImpl{
context={
    Person Age: 24
    Can Drive?: true
   }
}

@baldimir @yesamer

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:dmnRelated to DMNarea:engineRelated to the runtime enginestype:tech-debtThings that were left behind an may harm us in the future.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions