tkobayas commented on PR #6909:
URL: https://github.com/apache/incubator-kie/pull/6909#issuecomment-5616000126

   Hi @Rikkola , Sorry for the late comments. It's an interesting feature!
   
   The followings are findings from AI. They are ranked as important, but I 
think you may deal with them in separate PRs.
   
   ---
   
   ### 1. Mixed alpha + beta expressions in one step → `ClassCastException`
   
   When a single step has both an alpha expression and a beta expression 
referencing the anchor:
   
   ```java
   sequence(
           pattern(toy)
                   .expr("alpha", t -> t.getName().startsWith("a"))
                   .expr("beta", person, (t, p) -> 
t.getName().equals(p.getName()))
   )
   ```
   
   `PhreakNodeFactory` wraps the constraints in `CombinedAlphaConstraint`, 
whose `getRequiredDeclarations()` always returns an empty array. 
`DynamicFilter` then evaluates the whole thing as an alpha constraint and never 
supplies the anchor tuple to the beta part, which causes a `ClassCastException`.
   
   A single beta expression works fine (existing tests cover that). The issue 
is only with mixed alpha+beta in the same step.
   
   If supporting this combination is out of scope for now, it would be good to 
reject it at build time with a descriptive error.
   
   **Relevant code:**
   - `CombinedAlphaConstraint.java:54`
   - `PhreakNodeFactory.java:184`
   - `DynamicFilter.java:59`
   
   ### 2. Named consequence before a later sequence → wrong anchor skip
   
   When a named consequence sits between two sequences:
   
   ```java
   pattern(person),
   sequence(pattern(toy).expr("ball", ...)),
   when("always", person, p -> true).then(
           on(toy).breaking().execute(...)
   ),
   sequence(pattern(relationship).expr("go", ...))
   ```
   
   `buildSequenceVarIndexesForConsequence()` calculates `skip = totalSeqs - 1 - 
sequenceIndex`, but `totalSeqs` counts every sequence in the rule, including 
those after the named-consequence terminal. When the first sequence completes, 
its consequence has only one sequence anchor in the tuple chain but the 
compiler recorded `skip=1`, producing:
   
   ```
   IllegalStateException: SequencerFactSupplier: no SequencerMemory anchor 
found at skip=1
   ```
   
   The metadata should be calculated relative to each consequence terminal 
rather than the rule-wide total. Recording a sequence/node identity instead of 
a positional skip count would be more robust.
   
   **Relevant code:**
   - `KiePackagesBuilder.java:434-441`
   - `LambdaConsequence.java:396-406`
   
   ### 3. `.bind(...)` variables inside a sequence → `NullPointerException` in 
RHS
   
   ```java
   Variable<String> toyName = declarationOf(String.class);
   
   sequence(
           pattern(toy)
                   .expr("ball", t -> t.getName().equals("ball"))
                   .bind(toyName, Toy::getName)
   ),
   on(toyName).execute(name -> results.add(name))
   ```
   
   `buildStepGate()` records only `patternImpl.getPatternVariable()` in 
`sequenceVarIndexes`; variables from `.bind(...)` are not recorded and are 
absent from the activation tuple too, so the consequence fails with:
   
   ```
   NullPointerException: Cannot invoke "Declaration.getTupleIndex()" because 
"declaration" is null
   ```
   
   Since the API accepts a full `PatternDef` as a `SequenceStep`, its bindings 
should work. If that's intentionally unsupported, `.bind(...)` should be 
rejected during model construction or compilation.
   
   **Relevant code:**
   - `KiePackagesBuilder.java:627-632`
   - `LambdaConsequence.java:251-258`


-- 
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