mariofusco commented on code in PR #6788:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6788#discussion_r3511073702


##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/visitor/pattern/ClassPatternDSL.java:
##########
@@ -166,12 +169,36 @@ private Optional<Expression> 
buildFromDeclaration(PatternDescr pattern) {
     }
 
     private Optional<String> findFirstInnerBinding(List<? extends BaseDescr> 
constraintDescrs, Class<?> patternType) {
-        return constraintDescrs.stream()
-                .map( constraint -> 
ConstraintExpression.createConstraintExpression( context, patternType, 
constraint, isPositional(constraint) ).getExpression() )
-                .map( DrlxParseUtil::parseExpression )
-                .filter( drlx -> drlx.getBind() != null )
-                .map( drlx -> drlx.getBind().asString() )
-                .findFirst();
+        for ( BaseDescr constraint : constraintDescrs ) {
+            ConstraintExpression constraintExpression =
+                    ConstraintExpression.createConstraintExpression( context, 
patternType, constraint, isPositional( constraint ) );
+            if ( constraintExpression == null ) {
+                continue;
+            }
+            String expression = constraintExpression.getExpression();
+            if ( expression == null || expression.trim().isEmpty() ) {
+                continue;
+            }
+            DrlxExpression drlx;
+            try {
+                drlx = DrlxParseUtil.parseExpression( expression );
+            } catch ( RuntimeException e ) {
+                // This method only parses constraints to derive a name for an 
*unnamed* pattern. A
+                // constraint that doesn't parse here cannot declare an inner 
binding ($x : field) anyway,
+                // so deriving a name from it is impossible regardless; don't 
let it abort the whole
+                // KieBase build. Log which rule and pattern carry the 
offending constraint (to aid
+                // diagnosis), then skip. The actual constraint compilation is 
handled separately in
+                // findAllConstraint and will report a proper compilation 
error there if warranted.
+                LOG.warn( "Skipping a constraint that could not be parsed 
while generating an identifier for an " +
+                          "unnamed pattern of type {} in rule '{}'. Offending 
constraint expression: [{}] ({}: {})",
+                          patternType, context.getRuleName(), expression, 
e.getClass().getSimpleName(), e.getMessage() );
+                continue;
+            }

Review Comment:
   I agree with this comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to